实体框架 4 代码生成 - 一组实体?
我正在寻求为实体框架设置架构,将实体分解为多个模型。我想知道是否可以通过代码生成一组实体,以便每个模型使用同一组数据访问类?我意识到上下文的问题,但我想知道每个上下文是否真的需要有自己的一组类,或者我可以创建许多上下文,但只有一组代表后端表的类,使用自跟踪实体生成特征。
谢谢。
I am looking to setup architecture for entity framework that will break apart the entities into multiple models. What I am wondering if it is possible to code-generate one set of entities, so that each model uses the same set of data access classes? I realize the issue with contexts, but I was wondering if each context really needed to have its own set of classes, or I can create many contexts but only have one set of classes that represent the backend tables, using the self-tracking entities generation feature.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对可以跨多个模型共享 POCO 类。
例如,这样的类:
可以在将
Person
定义为ID,Firstname,Surname
的 EDMX 中工作并且可以在第二个 EDMX 中工作,该 EDMX 将
Person
定义为ID,Firstname,Lastname
虽然不确定自我跟踪实体,STE 是“POCO”,但它们也有一些模型如果两个 EDMX 中的 EntityType 定义不同(如我上面的示例),则可能会中断的特定代码。
你必须尝试一下。
希望这对
Alex(前 EF 团队成员)有帮助
You can definitely share POCO classes across multiple models.
For example a class like this:
Would work in an EDMX that defines
Person
asID,Firstname,Surname
And would work in a second EDMX that defines
Person
asID,Firstname,Lastname
Not sure though about Self-Tracking Entities, STEs are 'POCO' but they also have some model specific code which might break if the definition of the EntityType is different in your two EDMXs (like in my above sample).
You'd have to try it out.
Hope this helps
Alex (Former EF team member)