EF Hybrid - POCO(CTP5)和数据库生成的对象? [英] EF Hybrid - POCO (CTP5) and Database generated objects?

查看:41
本文介绍了EF Hybrid - POCO(CTP5)和数据库生成的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EF是否支持使用通过ctp5映射的代码优先对象(由他人设计)与数据库生成的实体?  它们是否在同一个实体集合中(手动我假设)并且无缝地生活和加入?

解决方案

我尝试了你的方案,看起来像它不可能首先做数据库并且首先编码,尽管那会非常好。我认为这个问题与connectionstring有关。当你创建一个模型时,connectionstring包含
ssdl,msl和csdl,因此它没有理由看到我为我的Context创建了一个部分类,并添加了另一个不在我的模型中的DbSet。 


我认为这将是一个很好的功能,因为它可以让我们消除设计师的许多限制。例如,有很多建模方案,设计师不支持,但运行时支持,所以我们要么使用
xml更改edmx,有时甚至不会让你打开设计器或不使用这些建模方案。首先使用代码进一步自定义模型或首先使用数据库,我们可以选择配置更改设计器不支持在代码中执行
。 


另一个好处示例很多时候我们想要自定义存储模型,但每次更新模型时,更改都会丢失。现在,如果我可以选择首先覆盖数据库的ModelCreating事件,那么我可以先在模型中对
进行更改。 


对于某些具有300的应用程序而言每个表格为150多列的表格,您必须使用设计器和代码生成,但使用Code First调整这些模型会很棒。


EF团队有什么想法吗?


Does EF support using code first objects (designed by others) mapped via ctp5 with database generated entities?  Would they be in the same entity collection (manually I presume) and live and join seamlessly?

解决方案

I tried your scenario and it seems like its not possible to be doing database first and code first together though that would be really nice. I think the problem has to do with the connectionstring. when you create a model, the connectionstring contains ssdl,msl and csdl therefore it sees no reason to see that i have created a partial class for my Context and added another DbSet that was not in my model. 

i think it would be nice feature to have because it would allow us to eliminate lot of restrictions the designer has. For instance there is lot of modeling scenarios which designer does not support but runtime supports so either we change the edmx using xml which sometimes wont even let you open the designer or not use those modeling scenarios. Having the ability further customize model first or database first using code first gives us an option to configure the changes designer does not support to do it in Code. 

Another good example is lot of times we want to customize the storage model but everytime you update the model the changes are lost. now if i had the option to override the ModelCreating event for Database first and Model first i can do those changes right there. 

For some applications that have 300 tables with each table being 150 plus columns, you have to use the designer and code generation but tweaking those models using Code First would be awesome.

Any thoughts EF team?


这篇关于EF Hybrid - POCO(CTP5)和数据库生成的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆