3
Why are relationships in the Entity Framework code first pointed to with Icollection? What is the best instantiation(?) for the property in common cases? List? Using the virtual keyword is only to enable Lazy loading on the property?
3
Why are relationships in the Entity Framework code first pointed to with Icollection? What is the best instantiation(?) for the property in common cases? List? Using the virtual keyword is only to enable Lazy loading on the property?
6
Because the lazy load of the Entity Framework puts in this property a dynamic proxy, which represents an object that implements ICollection
but that actually isn’t quite a collection of anything.
When accessing this property, the dynamic proxy is replaced there yes by a real collection (usually List<>
).
As follows:
public virtual ICollection<Objeto> Objetos { get; set; }
Not. virtual
indicates that the object can receive derivatives of the generic class. For example, you declare a Model called Alimento
and another call Fruta
, and makes Fruta
derive Alimento
. Thus declaring:
public virtual ICollection<Alimento> Alimentos { get; set; }
Alimentos
may also contain class objects Fruta
.
Browser other questions tagged c# entity-framework-6 code-first
You are not signed in. Login or sign up in order to post.