I have Customers, Invoice Headers, Invoice Details, and Products. All are one-to-many relationships.
My solution has a data layer project built using entity framework. I also have a models project with models for each entity. The data layer project references the models project.
So far, pretty typical.
The question is this...
Here is the CustomerModel:
public class CustomerModel : _ModelBase
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public List<InvoiceHeaderModel> InvoiceHeaders { get; set; }
}
I have this GetCustomer method on the DataLayer class:
public static CustomerModel GeCustomer(int CustomerId)
{
CustomerModel retVal = (from c in context.tblCustomers
where c.CustomerId == CustomerId
select new CustomerModel
{
CustomerId = c.CustomerId,
CustomerName = c.CustomerName
}).FirstOrDefault();
return retVal;
}
The problem is in this method I did not load the InvoiceHeaders property. If I did that here, would you also then load the invoice details, and then the products?
What if all I wanted was a simple list of Customers so that I could populate a simple list?
I could use lazy loading in the models, but that requires the Models to be coupled to the data layer. If I used eager loading here, how would I get the hierarcchy of models?
What's the right way to do this? .
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people