开发者

POCO in Entity Framework

I've read the concept of POCO in Entity Framework so many times but I didn't understand it. Although I've 开发者_如何转开发read links about POCO, I still need a clear explanation.


POCO just means that your entity classes don't have any persistence logic on them. That means that if you have an Order class it will never contain any methods that are used to get data from the db or save data to the db. You will never have an Order.GetById() or an Order.Save() method on a POCO. You also can't inherit from a base class that contains persistence logic (which is where EF1 fell down).

What your entity class will have is a bunch of properties that represent the data, and you'll probably have some validation methods, and maybe some business methods that operate on the order data, but you will not have persistence methods that get or save data. Persistence in a POCO architecture is handled by a separate class like a Repository or a DataService.

If you want more on what a POCO is I wrote a blog post that gives a longer explanation here http://rlacovara.blogspot.com/2009/03/what-is-difference-between-dto-and-poco.html.

The reason you see a lot written about POCO and Entity Framework is that EF1 made it almost impossible to implement a true POCO architecture. Many developers who care about things like ORMs want to use a POCO architecture so that was a big problem. With EF4 and especially EF4 CodeFirst Microsoft has made a lot of changes that make a POCO architecture pretty easy to implement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜