2
votes

What I think I understand (Please correct me if I am wrong)

  • POCO - Plain Old C# Objects. They are simple classes that dont inherit from anything?
  • STE - Self-Tracking Entities. they track changes on the individual entity objects so that when we do context.SaveChanges(); the changes on the entity objects are registered. This does not work on collections?

What I want to know?

  • If my context inherits from ObjectContext, does that mean I have POCO or STE? Similarly, is DbContext POCO or STE?
  • What does EF5 generate by default? POCO entities or STE? (I am using Model First)

Also can somebody give me some code examples representing these two types of entities?

2
POCO - Plain Old CLR Objects. - Yair Nevet
@YairNevet So if I wanted POCO entities, I would have to modify T4 template? Also, do you know how DbContext vs ObjectContext relate to POCO vs STE? - Joe Slater
Look at my updated answer. - Yair Nevet

2 Answers

2
votes

The IDE data designer, by default, creates an .edmx file which in earlier versions of Visual Studio (2008 and 2010) by default uses t4 templates that generate STE's by default and a context that derives from Object Context. In VS 2012, this was changed to generate POCO's by default with a context that derives from DbContext.

You can change this behavior by downloading a new code generator using NuGet.

2
votes

If my context inherits from ObjectContext, does that mean I have POCO or STE? Similarly, is DbContext POCO or STE?

If your context inherits from the ObjectContext class so you're probably have STE and DbContext working against POCOs. look here.

What does EF5 generate by default (Model first)? POCO entities or STE?

Model First, POCO and STE are 3 different things. In Entity Framework you are free to choose the best approach that compatible with your needs.

It could be:

  • Code-First
  • Model-First
  • Database-First

POCOs - Plain Old CLR Objects are "clean" classes that doesn't interspersed with database access functionality etc. and are considered as persistence-ignorance entities.

STE - Self Tracking Entities that are well aware to their persistence mechanism and considered as aware-persistnace.

Update: If you're working in the Model-First approach and would like to convert your entities (STE) to POCOs, you can use the EF 5.x DbContext Fluent Generator for C#