Friday, April 17, 2009 5:44 PM
I am able to eager load my one-to-many relationships to the client using the [Include()] attribute on the metadata class, however this technique does not work with my many-to-many relationships. My model is created with EF. I receive the following error when building after placing the [Include()] on the metadata property I wish to eager load.
"Invalid include specification for member '[EntityCollection]'. Non-projection includes can only be specified on members with the AssociationAttribute applied."
I added the [Association("[Name]", "KeyThis", "KeyThat")] to the property and received a successful build, however no eager loaded data is returned to the client. I would suspect its because it maps through a bridge tabe which is not supported on the [Association] attribute.
Any insight or tips?
Friday, April 17, 2009 5:50 PM
.NET RIA Services does not natively support many-to-many relationships in the current release. The workaround is to use the middle entity and 2 one-to-many relationships. We are looking into supporting this in the future...
Monday, April 20, 2009 1:58 AM
"We are looking into supporting this in the future..."
Wouldn't this enable people to "distribute" objects, and also try to move a "huge" domain model from the server side to the client side, just a thought ;)
Thursday, May 21, 2009 1:13 AM
Any idea when this will be supported?
Wednesday, January 06, 2010 6:01 PM
Is this supported in version 4.0? If so, how is it accomplished.
Wednesday, January 06, 2010 8:24 PM
No, many-to-many is not supported. You need to expose the linking table to create two one-to-many relationships.
Saturday, January 09, 2010 2:47 AM
I'm not sure how to expose the connecting table. I'm using EF VS2008 designer and it always just creates a relationship when I add the connecting table. Should I leave it that way and expose in RIA somehow? Or do I need to get dirty and edit the EF edmx by hand?
Thanks Colin, you rock!
Saturday, January 09, 2010 10:36 AM
You don't need to edit edmx by hand (at least, you don't need to manually edit the XML), you can do it through the editor. It is easiest to do this if you are starting from scratch.
If you have tables A, B, and AB then when you create the model only add A and AB to the model. Once the model is created, use the "update from database" to add B to the model. When this happens, B will ink to A instead of AB. Select the association from A to B and delete it. Draw a new association between AB and B. In the mapping window, set the associations map to AB and you should be fully linked up.
If you already have your model created, right click and "create new entity". Name the new entity AB and map it to the physical AB table. Delete the existing association between A and B and link the two to AB instead.
The third option is to modify your database by putting a new column in AB before you generate. The existance of a non-key column in the table will force it to be generated.
Saturday, January 09, 2010 10:48 PM
Third option worked like a champ. Add a 'temp' column to AB, then add A, B, and AB to the model, creates the proper linking, then deleted column 'temp'.
Thursday, May 26, 2011 11:20 PM
I realize this is an old thread... But is this still the case with RIA? After SP1?
Thursday, May 26, 2011 11:31 PM
There is a project on Codeplex called M2M4RIA that adds Many to Many support to RIA Services.