Why does the entity framework need an ICollection for lazy loading?

前端 未结 3 1512
醉酒成梦
醉酒成梦 2020-12-01 11:56

I want to write a rich domain class such as

public class Product    
{    
   public IEnumerable Photos {get; private set;}    
   public void A         


        
3条回答
  •  渐次进展
    2020-12-01 12:46

    You can overcome this by using the ReadOnlyCollection(Of T)

    public class Product    
    {  
        private IList _photos;  
        public IList Photos {
            get
            {
                return _photos.AsReadOnly();
            }
            private set { _photos = value; }
        }
        public void AddPhoto(){...}    
        public void RemovePhoto(){...}    
    }
    

    EDIT: ICollection => IList

    Hope that is what you were looking for.

提交回复
热议问题