本文介绍了EntityDataSource查询内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有3个表一个DB:

User{UserId,UserName}
Role{RoleId,RoleName}
User_Role{UserId,RoleId}

本查询:

int userIdPassByUrl = 0;
MyDbContext ctx = new MyDbContext();
var query = (from role in ctx.Role
        join userRole in ctx.User_Role on role.RoleId equals userRole.RoleId
        where userRole.UserId == userIdPassByUrl
        select new { role.RoleId, role.RoleName }).Distinct();



我需要显示在一个EntityDataSource的GridView上面查询的结果,无论是代码或设置它在设计模式

I need to show the result of the above query in a Gridview with an EntityDataSource, either code or set it in the design mode.

这是我的EntitydataSource:

this is my EntitydataSource:

<asp:EntityDataSource ID="EdsRolesByUser" runat="server"
        ConnectionString="name=myDbEntities"
        DefaultContainerName="myDbEntities" EnableFlattening="False"
        EntitySetName="Roles" EntityTypeFilter="Role"
        Select="it.[RoleId], it.[RoleName]">
    </asp:EntityDataSource>



任何帮助,将不胜感激,谢谢。

Any help would be appreciated, thanks.

推荐答案

终于得到了它。
不得不修改EntityDataSource去除EntitySetName和EntityTypeFilter
属性,并添加在CommandText是这样的:

Finally got it.Have to modified the EntityDataSource removing the EntitySetName and EntityTypeFilterattributes, and add the CommandText like this:

CommandText="SELECT DISTINCT userRole.RoleId, role.RoleName FROM Role AS role
INNER JOIN User_Role as userRole
ON role.RoleId = userRole.RoleId
WHERE userRole.UserId = @UserIdPassbyUrl"

这链接帮助我:

这篇关于EntityDataSource查询内部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 09:37