在实体框架上实现业务逻辑
我使用 ADO.NET 实体框架作为应用程序中的数据访问层,但我不确定应该将业务逻辑放在哪里。是否有任何最佳实践或示例可以说明如何将业务逻辑与实体框架实体集成?
编辑后:
我想要任何在 BLL 中实现计算、安全、规则和其他内容的示例... 任何文章和示例..!
I'm using the ADO.NET Entity Framework as the data access layer in my application, but I'm not sure where I should be putting business logic. Are there any best practices or samples available that illustrate how to integrate business logic with Entity Framework entities?
After Edit:
I want any samples with implement calculation,security,rules and other things in BLL ...
Any article and samples..!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该有一个业务层(引用数据访问层的单独项目或至少是业务对象所在的某种目录)。这些业务对象应该是直接与 DAL 通信的对象。换句话说,不要在 DAL 上实现业务逻辑,因为它不属于那里。
我确定您以前看过此图:
You should have a Business Layer (either a separate project that references your Data Access Layer or at least some sort of directory where your business objects reside). These business objects should be the ones talking to your DAL directly. In other words, don't implement business logic on your DAL since it doesn't belong there.
I'm sure you have seen this diagram before:
我不会将您的业务逻辑/规则放入实体框架中 - 它充当数据访问层。我将创建一个单独的业务逻辑项目(类库),它可以调用您的数据访问层来获取/设置数据并沿途强制执行业务规则,这样您就可以在数据访问层发生更改时重用这些规则。
I wouldn't put your business logic/rules in the Entity Framework - it serves as a data access layer. I would create a seperate business logic project (class library) this can call your data access layer to get/set data and enforce business rules along the way, this way you can reuse the rules should your data access layer change.
您可以使用实体作为业务对象。 实施业务逻辑 msdn 库文章解释了如何操作。如果您点击该链接,您将找到在属性更改期间和保存更改时适合业务逻辑的代码示例。
请记住,您可以使用自定义的部分类来扩展 EF业务逻辑。:
自定义对象 msdn 文章 。
涵盖此主题 rel="nofollow">在富 Internet 应用程序的 n 层解决方案 (RIA) 上,您可以将业务逻辑添加到域服务
You can use entities as business objects. Implement Business Logic msdn library article explain how do it. If you follow the link you will found code samples to fit business logic during Property Changes and when Saving Changes.
Remember that you can extend EF with partial classes with custom business logic.:
Customizing Objects msdn article also covers this topic.
On n-tier solutions for Rich Internet Applications (RIA) you can add Business Logic to the Domain Service