Prash's Blog

Entity Framework 4.0 supports POCO May 13, 2010

Filed under: C#,Entity Framework — prazjain @ 8:49 pm
Tags: , ,

POCO – Plain Old CLR Object

In Entity Framework 3.5 an Entity Class had to extend EntityObject class which in turn implemented IEntityWithKey, IEntityWithChangeTracker, IEntityWithRelationships. All of this meant more persistence logic into a domain object, a place where it does not belong. It also made testing of these domain object a bit more complicated.

Entity Framework 4.0 now supports POCO, so simple implementation like below could be used with EF 4.0 (database used with this example is the Microsoft AutoLot database).


public class Customers {

public int CustID {   get;   set;   }

public string FirstName {   get;   set;   }

public string LastName {   get;   set;   }

}

This also makes the code easier to test, and it extracts the persistence logic out of domain objects.