views:

158

answers:

1

I am using ASP.NET MVC2 on top of a MySQL database in VS2008. I am using the MySQL ADO.NET connector 6.2.3 to provide the connection for the ADO.NET Entity Data Model.

This is mostly working ok, however navigating via foreign keys is causing me a real headache!

Here is a simplified example..

Car (Table)
CarID PK
Colour
Doors
ManufacturerID FK

Manufacturer (Table)
ManufacturerID PK
Name

In the edmx file I can see the 1-many relationship shown as a navigation property in the both the Car and Manufacturer tables. I create a Models.CarRepository that allows me to returns a IQueryable.

At the View I want to be able to display the Manufacturer.Name for each car. This is not accessible via the object I get returned.

What is best way to implement this? Have I encountered a limitation of the Entity Framework/MySQL combination?

A: 

Eager loading of the related records needs to be enabled in the Model Repository. Something like:

var allCars = from c in automobileEntites.Car.Include("Manufacturer")
              select c;

This then makes the related records available for subsequent query/display.

Werg38