EntityDataSource查询内部联接

编程入门 行业动态 更新时间:2024-10-27 00:29:19
本文介绍了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 EntityTypeFilter attributes, 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"

这链接帮助我:的 msdn.microsoft/en-us/library/aa697427(v = VS.80)的.aspx

更多推荐

EntityDataSource查询内部联接

本文发布于:2023-10-15 00:44:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EntityDataSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!