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.
.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...
"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 ;)
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?
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.
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'.
bmahloch
Member
8 Points
14 Posts
eager load of many-to-many from entity framework
Apr 17, 2009 09:44 PM | LINK
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?
Thanks!
moravsky
Participant
1184 Points
218 Posts
Re: eager load of many-to-many from entity framework
Apr 17, 2009 09:50 PM | LINK
.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...
Fredrik N
Contributor
5184 Points
785 Posts
Re: Re: eager load of many-to-many from entity framework
Apr 20, 2009 05:58 AM | LINK
"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 ;)
MVP, ASPInsider, WCF RIA Services Insider
My Blog
beefster
Member
2 Points
6 Posts
Re: eager load of many-to-many from entity framework
May 21, 2009 05:13 AM | LINK
Hi,
Any idea when this will be supported?
Cheers,
Phil
slinton
Member
2 Points
5 Posts
Re: eager load of many-to-many from entity framework
Jan 06, 2010 10:01 PM | LINK
Is this supported in version 4.0? If so, how is it accomplished.
ColinBlair
All-Star
29925 Points
5031 Posts
Re: eager load of many-to-many from entity framework
Jan 07, 2010 12:24 AM | LINK
No, many-to-many is not supported. You need to expose the linking table to create two one-to-many relationships.
Upshot Blog
ColinBlair on Twitter
MVVM and RIA Services
sethian
Member
44 Points
58 Posts
Re: Re: eager load of many-to-many from entity framework
Jan 09, 2010 06:47 AM | LINK
Colin,
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!
Paul
ColinBlair
All-Star
29925 Points
5031 Posts
Re: Re: eager load of many-to-many from entity framework
Jan 09, 2010 02:36 PM | LINK
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.
Upshot Blog
ColinBlair on Twitter
MVVM and RIA Services
sethian
Member
44 Points
58 Posts
Re: Re: Re: eager load of many-to-many from entity framework
Jan 10, 2010 02:48 AM | LINK
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'.
Again, thanks!
PureWeen
Member
40 Points
44 Posts
Re: Re: Re: eager load of many-to-many from entity framework
May 27, 2011 03:20 AM | LINK
I realize this is an old thread... But is this still the case with RIA? After SP1?