Patrick Desjardins
Patrick Desjardins

Reputation: 140763

Entity Framework 4.3 Eager Loading Zero to many

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

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190905

I think you want to use ICollection<InvoiceDetail> instead.

Upvotes: 1

Related Questions