Question

I've got two projects with different database models (though the same Entity Framework Version 5.0.0).

Their queries look like the following:

Project 1:

if (_db.Entry(customer).State == EntityState.Detached)

Project 2:

if (customer.EntityState == EntityState.Detached)

These are the differences, as well as other minor things.

How can I tell which version of the Entity Framework (when the DLL version matches) each project is using? Does it make sense to update the "older" version to the "newer" model version? What are the benefits?

Was it helpful?

Solution

Project 1 uses the DbContext API because only this context type has an Entry method.

Project 2 most likely uses ObjectContext with entities derived from EntityObject and Customer inherits the EntityState from there. If Customer has a custom EntityState property, it's not possible to distinguish with your single line. Hit F12 twice - once on the customer variable which directs you to the declaration and then on the type (probably Customer) of that variable to see the class declaration and to check if it derives from EntityObject.

The fact that the EF5 assembly in Project 2 is referenced means nothing. It might be unused in the code or the code only uses a few helper methods (like the lambda version of Include), but it doesn't seem to use all the core features of DbContext. It will reference the EF classes in the .NET framework assemblies (System.Data.Entity.dll, etc.).

Upgrading project 2 is worth to consider because all newer development of EF follows the POCO approach (instead of the EntityObject approach).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top