Search code examples
ef-code-firstentity-framework-5wcf-ria-servicescrud

Entity Framework & RIA Services - CRUD on Link Table


After many hours, countless failures, I decided to change my Entity Model to include a link table in the model for each many-to-many relationship. This worked for me because RIA Services doesn't support many-to-many relationships.

Regardless, I'm able to build, but do not have any idea how to manage these relationships within the application itself. Should I create methods on the Domain Service, that are hidden from the client and used to perform CRUD operations on the link table objects?

An example would be greatly appreciated, thanks in advance.


Solution

  • I guess you already know http://m2m4ria.codeplex.com/ that adds many to many support to wcf ria services, however if you want to manage it by yourself, you better send it to the client and treat them like any other entities.
    You will not have Entity A with a collection of B entities and entities B with a collection of A entitities but rather:

    public class A
    {
        int Id {get; set;}
        ICollection<A_To_B> B_Entities {get; private set;}
    }
    public class A_To_B
    {
        int Id {get; set;}
        A EntityA {get; set;}
        int id_A {get; set;}
        B EntityB {get; set;}
        int id_B {get; set;}
    }
    public class B
    {
        int Id {get; set;}
        ICollection<A_To_B> A_Entities {get; private set;}
    }
    

    in your domain service add methods to correctly expose all of these entities and don't forget to properly decorate them (relationship is straight 1:m)