开发者

Poco class inherit entityobject

I have a t4 template which 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>();
        }
    
        priv开发者_开发知识库ate 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; }
        }
    
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜