Entity Framework 4.0 - EntityDataSource Many-To-Many Relation Query?
I want to perform a selection by 2 Entity ( AppRoles and AppUsers) ,
If in SQL, i would do this, For example :
SELECT u.*, r.* FROM AppUsers u ,AppRoles r WHERE u.RoleID = r.RoleID
Also it can be done using LINQ Syntax in Code-Behind.
However, i don't know how to do in EntityDataSource
Below is my mark-up :
<asp:EntityDataSource ID="edsUsers" runat="server"
ConnectionString="name=ReferralDBEntities"
DefaultContainerName="ReferralDBEntities" EnableFlattening="True"
EntitySetName="AppUsers"
Include="AppRoles"
Select="it.AppUsers, it.AppRoles"
Where="it.AppUsers.RoleID = it.AppRoles.RoleID"
>
</asp:EntityDataSource>
But it 开发者_开发技巧show the error.
assuming you want a list of all users in each role
and assuming you have a 3 table structure i.e. users, UserInRoles, UserRole
Then
<asp:EntityDataSource ID="edsUsers" runat="server"
ConnectionString="name=ReferralDBEntities"
DefaultContainerName="ReferralDBEntities" EnableFlattening="True"
EntitySetName="UserInRoles"
Include="UserRole, User"
Select="it.User.FullName, it.UserRole.Name">
</asp:EntityDataSource>
Job done
An older post not answered.
Try removing the Select="it.AppUsers, it.AppRoles"
Otherwise I am not sure how the relationship between your two tables is setup in the EDMX. You may want to check those also.
精彩评论