Repository模式,POCO,和业务实体 [英] Repository Pattern, POCO, and Business Entities

查看:200
本文介绍了Repository模式,POCO,和业务实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多的线程在这里已经在仓库模式,但不知何故,我觉得我的问题是有一点不同。也许是因为昨天是我第一次听到这个词POCO的。

I know there are a lot of threads here already on the repository pattern but somehow I feel my question is a little different. Maybe because yesterday was the first time I heard of the word POCO.

我的问题是 - 通常情况下,我已经添加和保存在我的业务实体的方法。说我写一个Q / A网站,我有以下实体:问题,答案和注释。如果我想使用这个资源库的模式,基本上,我需要让我的业务实体(例如,问题)只有属性,并提出我的操作到仓库类(例如,QuestionRepository),对不对?如果这是真的,确实POCO意味着只用性质的业务实体?

My question is this--usually, I have add and save methods in my business entities. Say I am writing a Q/A site, and I have the following entities: questions, answers, and comments. If I wanted to use the repository pattern, I basically need to keep only the properties in my business entities (example, Question), and move my operations to the repository class (example, QuestionRepository), right? If this is true, does POCO mean a business entity with just the properties?

我使用实体框架4.0,它创造了我的实体在EDMX code后面。如果我想使用这个资源库模式与此,没有必要写我自己的业务实体(问题,答案等),因为他们已经由EF产生的,对不对?所有我需要的是库做CRUD?而我将有三个库在这个例子中,每个实体?

I'm using Entity Framework 4.0, which created my entities in the edmx code behind. If I wanted to use the repository pattern with this, there is no need to write my own business entities (Question, Answer, etc) since they are already generated by EF, right? All I'd need is the Repository to do CRUD? And I'll be having three repositories for this example, one for each entity?

推荐答案

您POCO的对象仍然有它们的方法进行操作,但是这些操作会涉及到实体而不是持久性的担忧(CRUD)的企业的关注。如果没有商业运作上你的entites,那么是的,他们将只是属性。

Your POCO objects would still have methods on them for operations, but those operations would pertain to the business concerns of the entity not the persistence concerns(CRUD). If there are no business operations on your entites, then yes they will be just properties.

您不会需要从头开始,如果您正在生成他们写你波苏斯,但你可能希望将它们与部分类业务和非持续性或计算性能扩展。

You wouldn't need to write your pocos from scratch if you are generating them but you may want to extend them with partial classes for business operations and non-persistent or calculated properties.

您可以有一个单一的存储库类或为每个实体的存储库。

You could have a single repository class or a repository for each entity.

这篇关于Repository模式,POCO,和业务实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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