简体   繁体   English

向我的Entity Framework POCO类添加功能

[英]Adding functionality to my Entity Framework POCO classes

I've built a web application with Entity Framework using POCO. 我已经使用POCO使用Entity Framework构建了一个Web应用程序。

I'm using these POCO classes as my business objects and not just for persisting data which works fine until... 我将这些POCO类用作我的业务对象,而不仅仅是用于持久保存数据,直到...

Now I need to add some logic into these classes to do thing like total up sales, order lines, etc. 现在,我需要在这些类中添加一些逻辑以执行诸如总销售额,订单行等操作。

Should I add methods to my POCO classes to enable this functionality or leave them purely for persisting data and create some kind of 'processor' whereby I pass in the business objects and get the values I require out. 我应该在POCO类中添加方法以启用此功能,还是将它们留给纯粹用于持久数据并创建某种“处理器”,以便我传入业务对象并获取所需的值。

Is there a best practice for this? 是否有最佳做法?

What is the architectural design you are using or want to use? 您正在使用或想要使用什么建筑设计?

For example, if these are your domain entities, you should put as much as possible logic in them. 例如,如果这些是您的域实体,则应在其中放入尽可能多的逻辑。 If they are merely data containers and you don't have a real architecture in place, your logic would probably in some business component. 如果它们只是数据容器,而您没有合适的体系结构,则您的逻辑可能会包含在某些业务组件中。

So if you provide your question with some more details, we can help you better. 因此,如果您为问题提供更多详细信息,我们将为您提供更好的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM