Joe Slater
Joe Slater

Reputation: 2473

Self-Tracking Entities and POCO explanation needed

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

What I want to know?

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

Upvotes: 2

Views: 497

Answers (2)

Yair Nevet
Yair Nevet

Reputation: 13013

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#

Upvotes: 2

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93464

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.

Upvotes: 2

Related Questions