EDM Query associations

The good thing about the entity framework is, that it hides the complete n..m association problem.

Now I have some really simple Database containing

Person (Id, Name)
Profession (Id, Designation)

there is a n..m association between those two, meaning every person can have many Professions and every Profession can be executed by many Persons. This association is built on the Id in each entity.

Now I want to have exactly those Associations, but there seems to be no way to get those.

If I query a Person like

using (PersonDataModelContainer dmc = new PersonDataModelContainer())
{
    var persons = (from p in dmc.Persons
                   where p.Id == personId
                   select p).ToList();
}

There is a member "Profession", but it is empty. In the Associationstable there are entries that correspond to this Person.Id.

I see somewhere down in the single object this query returns that there are the relations in a non public member.

How can I read those? Should not be that hard I believe, but I could not find it out via google.

Answers


using (PersonDataModelContainer dmc = new PersonDataModelContainer())
{
    var persons =  dmc.Persons
                   .Include("Profession")
                   .Where(p.Id == personId)
                   .ToList();
}

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.