实体框架4代码生成 - 一组实体? [英] Entity Framework 4 Code Genning - One Set of Entities?

查看:48
本文介绍了实体框架4代码生成 - 一组实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,


我希望为实体框架设置架构,将实体分解为多个模型。我想知道是否有可能代码生成一组实体,以便每个模型使用相同的数据访问类集?
我意识到了上下文的问题,但我想知道每个上下文是否真的需要拥有自己的一组类,或者我可以创建许多上下文但只有一组表示后端表的类,使用自我 - 跟踪实体生成
功能。


谢谢。



http:/ /linkedin.com/in/brianmains

解决方案

< span style ="font-family:Calibri">你好bmains,


 


欢迎来到EF论坛!


 


< p style ="margin:0in 0in 0pt"> 不同的模型可以共享相同的实体。 
但是,实体数据模型(.edmx)包含的实体类必须满足每个模型中的请求&s;
CSDL定义 &NBSP;
  CSDL定义也应该映射到
SSDL定义 正确通过
MSL规范   


 


例如如果表A和表B在模型1中具有一对多关系,表A和表C在模型2中具有一对多关系,则实体A必须包含对实体B和实体的导航
属性C.     当您在不同的上下文中使用实体A时,它可能会非常复杂,您是否这么认为?


 


美好的一天!


 


 


< span style ="font-size:12pt"> 最诚挚的问候,b
Lingzhi Sun


MSDN Subscriber Support
在论坛


如果您对我们的支持有任何反馈,请联系
msdnmg@microsoft.com


Hello,

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.


http://linkedin.com/in/brianmains

解决方案

Hi bmains,

 

Welcome to EF forum!

 

Different models can share the same entities.  However, the Entity Data Model (.edmx) contains Entity classes must meet the request in each model’s CSDL definition.   Also the CSDL definition should be mapped to the SSDL definition correctly via MSL specification.  

 

E.g. If Table A and Table B have one-to-many relationship in Model 1, Table A and Table C have one-to-many relationship in Model 2, the Entity A must contain navigation properties to both Entity B and Entity C.   It can be really complicated when you use the Entity A in different context, do you think so?

 

Good day!

 

 

Best Regards,
Lingzhi Sun

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


这篇关于实体框架4代码生成 - 一组实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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