Witam, wiem że tytuł jest bardzo mało zrozumiały ale tutaj postaram się to bardziej wytłumaczyć. O co mi chodzi:
Tworzę projekt na zajęcia na studiach i korzystam w nim z Entity Frameworka (6.4.0) mam w nim kilka encji, ale narazię chce się skupić na dwóch.
public class Product : IEntity
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal Price { get; set; }
public int StoreID { get; set; }
public Store Store { get; set; }
}
i
public class Store : IEntity
{
public int StoreId { get; set; }
public int AddressId { get; set; }
public Address Address { get; set; }
public ICollection<Product> Products { get; set; }
public int ContractorId { get; set; }
public Contractor Contractor { get; set; }
}
Dalej mam obsłużone dodawanie i zwracanie wartości z bazy mam obsłużone i to działa poprawnie poza jedną rzeczą.
Kiedy staram się sięgnąć po Produkt i dalej do jego Sklepu i wybrać stamtąd jakąś wartość to Store jest nullem.
static void Main(string[] args)
{
IProductService productManager = new ProductManager(new ProductDal());
productManager.Add(new Product { ProductName = "Tangerines", Price = 50, ProductId = 1, Store = new Store() { Address = new Address(), Contractor = new Contractor() } });
productManager.GetAll().ForEach(x => Console.WriteLine(x.Store.ContractorId)); //Tu jest null
Console.ReadLine();
}
W jaki sposób mogę się dostać do tej zmiennej? Myślałem że Entity Framework jakoś to połączy, ale w tym wypadku to niestety nie działa.
Za wszelką pomoc bardzo dziękuje :)