views:

18

answers:

1

I have a t4 template wich generates my poco classes. Everything is working fine. Now, i want to inherit those classes from EntityObject (i want to know about EntityState sometimes) but when i do this, the relationships are always returning null (lazy loading not working). Any suggestions ?

Here is a simple model

    public partial class Customer
    {

        public Customer()
        {
            addresses = new List<Address>();
        }

        private ICollection<Address> addresses;

        public virtual int ID
        {
            get;
            set;
        }

// if Customer inherits from EntityObject, this prop will always returns null
        public virtual ICollection<Address> Addresses
        {
            get { return addresses; }
            set { addresses= value; }
        }

    }
A: 

That is completely wrong. The only reason for introducing POCO in EF 4.0 is to have entities that are NOT inheriting from the EntityObjects. If you care about the EntityState, you should use Self-Tracking Entities or just make them to be default EntityObjects generated by EF.

Morteza Manavi