5
I’m starting in Entity Framework and I have a question regarding Codefirst. Why I have to use as virtual some properties like the example below?
[Table("Grupo")]
public class Grupo
{
public int ID { get; set; }
[Required(ErrorMessage="Nome não pode ser branco.")]
public string Nome { get; set; }
public virtual IQueryable<Produto> Produtos { get; set;}
}
Good evening Cigado, excuse my ignorance. I did not understand the meaning of what would be a Dynamic Proxy. And on the virtual, you mean then that he is not responsible for making the association between the entities, ie the classes? Another question, always have to be used the Icollection interface or can be used also Ienumerable? Thanks!
– Kelly Soares
Dynamic proxy is a class that pretends to be another. In the case of lazy load, instead of a list of Products being loaded, it is placed at the initialization of a
Grupo
a Dynamic Proxy that pretends to be a list of Products. These Products will only be loaded effectively when you call up this list in some way (in ASP.NET MVC, it’s usually at View). Then the EF carries the Products from the bank to you.– Leonel Sanches da Silva
About being
ICollection
orIEnumerable
, even works forIEnumerable
, butICollection
has some more features, being a more comprehensive interface. Hence my recommendation.– Leonel Sanches da Silva
@Kellysoares I recommend you ask another question and mark this as accepted, if she solved your question.
– Leonel Sanches da Silva