Reputation: 140763
I have a database that look like this:
[Invoice]
-PK:ID
-...
[InvoiceDetail]
-PK:ID
-FK:Invoice_ID
-...
I have my C# Objects that look like this:
[Invoice]
public virtual IEnumerable<InvoiceDetail> InvoiceDetails { get; set; }
...
[InvoiceDetail]
...
When I try to use:
MyDbContext.Invoices.Where(inv => inv.Id == 1).Include("InvoiceDetails").FirstOrDefault();
//or
MyDbContext.Invoices.Include("InvoiceDetails").Single(inv => inv.Id == 1);
I have an exception :
A specified Include path is not valid. The EntityType 'DataAccessLayer.Database.Invoice' does not declare a navigation property with the name 'InvoiceDetails'.
I do not understand why it search 'DataAccessLayer.Database.Invoice' which doesn't have its model there. I also doesn't understand the "navigation property" because I am using Poco object (code first).
Any one know how I can do this zero to many relationship?
Upvotes: 0
Views: 358
Reputation: 190905
I think you want to use ICollection<InvoiceDetail>
instead.
Upvotes: 1