业务实体,数据访问层 - 循环引用
我是 EF4 的新手,正在尽力遵循指导,所以我选择走 POCO 路线,并将 POCO 类放在自己的项目中。我已经在 DataAccess 项目中添加了存储库类,当然 DataAccess 项目引用了 POCO 项目。
我目前正在向 POCO 类添加业务功能,但遇到了一个障碍,其中一个 POCO 对象上的特定方法创建了一堆其他 POCO 对象,这很酷。但是,它创建的 POCO 对象已经在数据库中,所以知道我需要我的 BusinessEntity 项目来引用 DataAccess 项目,这当然会创建循环引用。
在此领域的任何指导将不胜感激。
I am new to EF4 and are trying to follow the guidance as best I can, so I have choosen to go down the POCO route and have put the POCO classes in there own project. I have added repository classes in the DataAccess project and off course the DataAccess project reference the POCO project.
I am currently adding business functionality to the POCO classes and hit a snag where a particular method on one of the POCO objects creates a bunch of other POCO objects, which is cool. BUT, the POCO objects that it creates are already in the database so know I need my BusinessEntity project to reference the DataAccess project which of course is creating a circular reference.
Any guidance in this space would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望我没有误解您的问题,但听起来您可能想要使用 DTO(数据传输对象)类型的路由。我自己是 EF 新手,但目前正在从事 EF、WCF、WinForms 项目。我有 WCF 服务的合约对象,用于将数据发送回客户端。我将属性从 EF 实体映射到业务层中的 DTO 对象。我使用 DTO 是因为我的客户端不需要 EF 实体的所有属性。 尝试此链接。我发现了一些关于项目结构的非常好的东西。希望这有帮助。
Hopefully I'm not misunderstanding your issue, but it kind of sounds like you may want to go with a DTO (Data Transfer Objects) type route. I am new to EF myself but am currently working on an EF, WCF, WinForms project. I have contract objects for my WCF service that I use to send data back to the client. I map properties from my EF Entities to my DTO objects in my business layer. I use DTOs because my client does not need all the properties of the EF Entity. Try this link. I found some really good stuff regarding project structure. Hope this helps.