I’m using ADO.Net Entity Framework and C# to retreive the languages of a destination using this:
var list =
from dd in guiaContext.DestinationDetail
where dd.id_destination == destinationID
select dd;
But when I access language in a foreach:
foreach (DestinationDetail detail in list)
languagesList.Add(detail.Language.ds_language);
detail.Language is null. Why?
Thank you!
Is there 2 tables : destination and language ?
Is there a foreign key relationshipt between the destination and language table ?
That would help in commenting on the above problem of language being null.
By default EF does not retrieve the referenced table (lazy loading).
Try this :
var list = from dd in guiaContext.DestinationDetail Include(“Language”) where dd.id_destination == destinationID select dd;
Look at the following link on eager loading in Entity Framework:
http://msdn.microsoft.com/en-us/library/bb896272.aspx