I have 2 classes related in my model:
public class Product
{
public Product()
{
this.Additives = new HashSet<Additive>();
}
public int Id { get; set; }
public string Name { get; set; } // refrigerante
public string CommercialName { get; set; } // nome popular, ex: fanta laranja
public string Brand { get; set; } // marca, ex: Coca-cola
public string Details { get; set; } // composicao, ingredientes
public HalalState HalalState { get; set; } // estado: halal, haram ou desconhecido
public DateTime? LastUpdate { get; set; } // date e hora do registo
public ICollection<Additive> Additives { get; set; } // aditivos
public int ProviderID { get; set; }
}
and
public class Provider { public Provider() { this.Products = new HashSet(); }
public int ProviderId { get; set; }
public string OfficialName { get; set; } // nome usado no licenciamento
public string PopularName { get; set; } // nome popular, mais conhecido
public int Nuit { get; set; } //identificacao tributaria
public EstablishmentCategory EstablishmentCategory { get; set; } // tipo de estabelecimento
public HalalState HalalState { get; set; }
public DateTime? LastUpdate { get; set; } // date e hora do registo
public ICollection<Product> Products { get; set; } // lista de produtos halal
}
I'm trying to load products alongside with its provider name to display in page using Razor engine. Something like:
Product Name (from table A) | Provider Name (from table B)
Soft drink | Coca-Cola
Chips | Lays
The method to retrieve products in class ProductsRepository:
public ICollection<Product> ReadAll()
{
return context.Products.ToList();
}
I need a way to navigate to OfficialName property of the Provider class, in order to display it alongside another properties of Product in a view.