Ehsan Ghanbari

Experience, DotNet, Solutions

What's the meaning of POCO entity and Persistence ignorance

POCO which stands for "Plain Old CLR Objects" is an entity/class and doesn’t depend on any specific base class. It is like any other Dot net class you have seen before. These POCO entities (also known as persistence-ignorant objects) also support most of the same LINQ queries you use in you Data access layers for your business objects.  POCO is a simple object to be used with a complicated, special object framework such as an ORM component. In other definition POCOs are entities of your domain, so When you use entity framework, these entities are generated for you. You can also use code generators to generate these entities. POCOS are just simple entities without any data access functionality but still gives the capabilities all EntityObject functionalities like Lazy loading and Change tracking

Persistence ignorance means that, as much as possible, anything in your code operating at the business logic layer or higher knows nothing about the actual design of the database, what database engine you're running, or how or when objects get retrieved from or persisted to the database. The domain objects should be ignorant of persistence logic. For example, instead of calling Product.Save(), it's better to call Repository.Save(product). In this way, you get better separation of concerns and avoid exposing persistence semantics on your business objects. The Entity Framework enables you to use custom data classes together with your data model without making any modifications to the data classes themselves. This means that you can use "plain-old" CLR objects (POCO), such as existing domain objects, with your data model. Although these days most of the people like to go through the Code first approach and create their own POCO classes instead of create POCO entities after creating the database.

Notes:

  1. POCO entities are not always needed to be hand-craft.
  2. Lazy loading works with POCO entities.
  3. Entity framework and Nhibernate both support for lazy loading of POCO
  4. POCO cannot use inheritance with your complex type classes
  5. complex types with POCO only supported  Complex Type is class.

 

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in asp.net MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In asp.net MVC
Multiple submit buttons in asp.net MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
comments powered by Disqus