0
I have the class Cliente who owns a IList<Produto> and the class of produto has a ClienteId (which is FK) and an attribute Cliente Cliente { get; set; }. How to access the attribute Nome of Cliente as a product?
public class Cliente
{
....
public string Nome {get;set;}
public IList<Produto> Produtos {get;set;}
}
public class Produto
{
....
public int ClienteId {get;set;}
public Cliente Cliente{get;set;}
}
NOTE: all fields are mapped, and are bringing data.
I didn’t understand if you have something more or your doubt is simpler than I think. But if all the data is being filled in, just use
produto.Cliente.Name, beingprodutothe instance of the classProduto. There is also a typo in your classes, is referencing the classProdutobut the class name isProdutos.– Gabriel Heming
I wanted to access the property
NomeofClienteinProduto,&#I tried that wayProduto.cliente.NomeandProdutoClienteNome, and not for sure.– Vinicius
Tried to access properties via debug? Is there an error trying to access? Intellisense gives the name of the properties?
– Gabriel Heming
@Vinicius, try to change the Client property as virtual, to allow Entity to do Lazy loading.
– Junior Porfirio
@Juniorpirio worked out to change to virtual
– Vinicius