有没有人使用将实体代码优先与edmx文件混合使用的Entity Framework? [英] Have anyone used Entity Framework with code first approach mixed with Edmx file?

查看:129
本文介绍了有没有人使用将实体代码优先与edmx文件混合使用的Entity Framework?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在分配一个项目,在该项目中他们的遗留系统以可怕的方式进行设计,并且过于关注数据库设计.我试图提出一种新设计,使客户可以一点一点地迁移旧系统.

I'm currently assign to a project where their legacy system is designed in a horrible way and it's been too much focus on database design. I trying to put together a new design where the customer can migrate the legacy system bit by bit.

他们当前使用的是EF 4.1,但edmx文件中没有使用实体描述/映射的代码优先方法.他们每次都要进行逆向工程以扩展模型(首先在数据库中进行更改,然后通过自定义工具将其向上反映到模型层).

They are currently using EF 4.1 BUT not code first approach with entity descriptive/mapping is located in an edmx file. They do Reverse engineering everytime to want to extend the model (First make changes in database, then reflect them upwards to Model layer through a custom tool).

我想知道的是,如果有人同时使用edmx和代码优先方法与映射类.还有缺点要知道吗?

What I would like to know, if anyone has used BOTH edmx and code first approach with mapping classes. And is there drawbacks to know about?

推荐答案

仅当每种方法具有单独的上下文类型(不能在单个上下文类型中混合使用方法)时,才可以一起使用EDMX和代码映射.这可能是最大的缺点,因为它会导致更复杂的代码和维护.

You can use EDMX and code mapping together only if you have separate context type for each approach (you cannot mix approaches in single context type). That is probably the biggest disadvantage because it leads to more complex code and maintenance.

例如,如果您需要在两种上下文类型中都具有某个实体以将其与新代码和旧代码一起使用,则必须两次维护其映射.您还必须非常小心,不要复制实体类本身=您的代码必须首先使用由自定义工具为EDMX生成的类,但是如果他们在当前解决方案中未使用POCO,那么这将是不可能的.

For example if you need to have some entity in both contexts types to use it with both new and legacy code you must maintain its mapping twice. You must also be very careful about not duplicating entity class itself = your code first must use class generated by custom tool for EDMX but this will not be possible if they are not using POCOs in current solution.

另一个问题将是数据库完整性.如果您需要在单个事务中保存对两种上下文类型的更改,则必须使用TransactionScope和分布式事务= MSDTC(每个上下文实例将处理其自己的数据库连接).

Another problem will be database integrity. If you will need to save changes to both context types in single transaction you will have to use TransactionScope and distributed transaction = MSDTC (each context instance will handle its own database connection).

如果您确定将迁移整个系统,则可以考虑先使用代码而不是EDMX(但请注意,代码优先映射和DbContext通常提供更多有限的功能集).如果您不确定是否能够完成整个迁移,甚至不要考虑先使用代码,因为让系统处于一半先使用代码而一半使用EDMX的状态只会使一切变得更糟,也更加可怕.

If you are sure that whole system will be migrated you can probably think about using code first instead of EDMX (but be aware that code first mapping and DbContext generally offers more limited feature set). If you are not sure that you will be able to complete whole migration don't even think about using code first because leaving system in the state where half uses code first and half EDMX will make everything only worse and much more horrible.

要确定一点理论,因为在软件开发中,您唯一可以确定的是需求/情况将会改变.这意味着应该非常仔细地考虑迁移.

Being sure is little bit theoretical because in SW development the only think you can be sure about is that requirements / situation will change. It means that migration should be very carefully considered.

这篇关于有没有人使用将实体代码优先与edmx文件混合使用的Entity Framework?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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