I'm wondering if anyone can give a solid explanation (with example) of POCO (Plain Old CLR Object). I found a brief explanation on Wikipedia but it really doesn't give a solid explanation.
相关问题
- How to Specify a Compound key in Entity Framework
- Entity Framework 4.0 Autogenerated Classes not mar
- How to map parent column in EF 4.1 code first
- How to make POCO work with Linq-to-SQL with comple
- How to extend C++ HTTP server with FastCGI applica
相关文章
- POCO Vs Entity Framework Generated Classes? [close
- What is the best practice to deal with navigation
- Custom setter for C# model
- Lucene.NET through NHibernate.Search and POCO Enti
- what is the best practice to set up DbContext in S
- Adding methods to POCO classes
- Multiple Http Servers with Poco and Boost C++
- EF CodeFirst: Get all POCO types for DbContext
Example of a POCO:
You need to give more details, such as the context in which you are planning to use POCO. But the basic idea is that you will create simple objects containing only the data/code that is necessary. These objects would not contain any "baggage" such as annotations, extra methods, base classes, etc that might otherwise be required by (for example) a framework.
Instead of calling them POCOs, I prefer to call them persistence ignorant objects.
Because their job is simple, they don't need to care about what they are being used for or how they are being used.
Personally I think POCOs are just another buzzword (like Web 2.0 - don't get me started on that) for a public class with simple properties.
I've always been using these type of objects to hold onto business state.
The main benefits of POCOs are really seen when you start to use things like the repository pattern, ORMs and dependency injection.
In other words - you could create an ORM (let's say EF) which pulls back data from somewhere (db, web service, etc), then project this data into objects (POCOs).
These objects can be passed further down the app stack to the service layer, then onto the web tier.
Then if one day you decide to switch over to nHibernate, you should not have to touch your POCOs at all, the only thing that should need to be changed is the ORM.
Hence the term 'persistence ignorant' - they don't care what they're being used for or how they are being used.
So to sum up, the pros:
Hope that helps.