Search code examples
silverlightentity-framework-4linq-to-entitiesriadomainservices

entity/ria include many to many


ok, I know this is asked a million times, but I still can't seem to find a working solution. Hopefully I'm just missing something. Using entity with silverlight, through RIA I have a many to many table structure in my DB.

[System] - [SystemUsers] - [Users] 

The bridge table just has the two IDs so naturaly entity doens't include it in the model.

I know RIA doesn't like many to many relationships, so I've added Association attribute tags to the collection, and can now at least see the collection property on the client side.

[Association("DMSSystem_Users", "DMSSystemId", "UserId")]
[Include]
[Composition]
public EntityCollection<Users> Users { get; set; }

In my domain service I've tried including the users:

public IQueryable<DMSSystem> GetSystem()
{
    return this.ObjectContext.DMSSystem.Include("Users");
}

I never get the users on the client side Is there something else I am missing to get the users to be inculded and sent to the client?


Solution

  • RIA with EF has a dislike for M:M relationships. What you need to do is to help RIA see the M:M as two 1:M relationships.

    On your link table add an extra column (I add something like IgnoreThisField) and make it a bit type.

    When EF sees this table it will now interpret it differently allowing you to handle the M:M relationship.