[英]Entity Framework - in model first, how do I get my EF classes to be based on the existing domain classes I have?
If I already have domain classes, and I want to be able persist them using EF via a model first approach how do I do this? 如果我已经拥有域类,并且希望能够通过模型优先方法使用EF来持久化它们,该如何做?
For example do I go to the EF designer (in VS2010) and create the model and generate the classes, then go to these EF classes and somehow manually modify them? 例如,是否要去EF设计器(在VS2010中)并创建模型并生成类,然后去这些EF类并以某种方式手动修改它们? But then would there be an issue if I needed to change the model and re-create database TSQL from the model for updates?
但是如果我需要更改模型并从模型中重新创建数据库TSQL进行更新,那会不会有问题?
What's the easiest approach? 最简单的方法是什么?
EDIT - In my case I've got some base classes that do graph navigation - I was hoping I could leave (a) my graph traversal routines in the business logic assembly, eg NodeBase, RelationshipBase etc, and then (b) have my EF persistance in a separate EF assembly. 编辑-就我而言,我有一些进行图导航的基类-我希望我可以(a)将图遍历例程留在业务逻辑程序集中,例如NodeBase,RelationshipBase等,然后(b)使用我的EF坚持在一个单独的EF程序集中。 Any advice on this specific scenario I have?
我对此有什么建议?
EDIT 2 - Actually I note I note the following template options from "Add Code Generation Item.." 编辑2-实际上,我注意到我注意到“添加代码生成项..”中的以下模板选项。
I'm guessing the #3 one is the default that comes with VS2010. 我猜想#3是VS2010随附的默认值。 Anyone across #1 and #2 and which might be best to assist in my goal?
#1和#2中的任何人,哪个可能最有助于实现我的目标? ie Having an existing set of domain classes with methods that already inherit from other classes (ie noting with the current EF generated entity classes they seem to already have to inherit from EntityObject)
即拥有一组现有的域类,这些域类具有已经从其他类继承的方法(即注意当前EF生成的实体类,它们似乎已经必须从EntityObject继承)
The generated classes are all partial. 生成的类都是局部的。 So if you have the same namespace and same Entity/Class names it's fairly easy to merge an existing set of classes with a model-first set of entities.
因此,如果您具有相同的名称空间和相同的实体/类名称,则将现有的类集与模型优先的实体集合并是相当容易的。 Simply put partial on your class and remove all the properties that are implemented by the Entity framework generated code.
只需将partial放在您的类上,并删除由Entity Framework生成的代码实现的所有属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.