2

I have a set of tables in MySQL - Customer 1-many Order 1-many OrderProduct many-1 Product.

I generated an EF model from the database, and other than this issue, it's working well.

If I load a given Customer, I get their Orders and OrderProducts as expected. But the Navigation property (FK) joining the OrderProduct match table to the Product table won't load.

I've actually copied the generated SQL into a MySQL query window and I do get the joined data from the Product table. But the data isn't apparently mapped into the class on return.

I've tried any number of eager/lazy loading combinations, including what's in there now:

context.orders.Where(o => o.UserID == UserID && o.OrderDate == OrderDate.Value)
              .Include(o => o.orderproducts.Select(p => p.product))
              .First();

But no matter what I do, product is always null.

Any suggestions?

4

1 回答 1

0

尝试这个:

var order = context.orders.Include("orderproducts.product")
              .Where(o => o.UserID == UserID && o.OrderDate == OrderDate.Value)
              .First();
于 2012-11-10T07:51:02.633 回答