[英]how to get the data from entity frame join tables?
I'm using entity frame work
. 我正在使用
entity frame work
。 I create a function using 3 tables. 我使用3个表创建一个函数。
this is my code: 这是我的代码:
public static IQueryable GetMenuContent()
{
string roleName ="ADMIN"
var query1 = from ua in db.USER_ACCESS
join p in db.PAGES on ua.PAGE_ID equals p.PAGE_ID
join r in db.ROLES on ua.ROLE_ID equals r.RoleId
where (r.RoleName == roleName)
select new
{
tuserAccess = ua,
tpage = p,
trole = r,
};
return query1;
}
So in my master page I need to check the USER_ACCESS
table -> PAGE_NAME
. 因此,在我的母版页中,我需要检查
USER_ACCESS
表-> PAGE_NAME
。
So I try like this 所以我尝试这样
@foreach (var item in pro.Models.SiteContentModel.GetMenuContent())
{
switch (((DAL.PAGES)(item)).PAGE_NAME)
{
case "details":
if (((DAL.USER_ACCESS)(item)).ACC_STATUS == true)
{
<li>@Html.ActionLink("details", "Index", "Business")</li>
}
break;
}
}
but it is not working.. How can I do it.. 但它不起作用..我该怎么办..
You should use navigation properties instead of joins in your case. 在这种情况下,应使用导航属性而不是联接。
But in your case you should rewrite your foreach: 但是在您的情况下,您应该重写foreach:
@foreach (var item in pro.Models.SiteContentModel.GetMenuContent())
{
switch (item.tpage.PAGE_NAME)
{
case "details":
if (item.tuserAccess.ACC_STATUS == true)
{
<li>@Html.ActionLink("details", "Index", "Business")</li>
}
break;
}
}
Try modifiyi g the method as follow. 尝试按以下方法修改方法。 Your anonymous objcet's property accsing is changed.
您的匿名objcet的属性访问已更改。
((DAL.t_PAGES)(item)).tpage.PAGE_NAME ((DAL.USER_ACCESS)(item)).tuserAccess.ACC_STATUS ((DAL.t_PAGES)(项目))。tpage.PAGE_NAME((DAL.USER_ACCESS)(项目))。tuserAccess.ACC_STATUS
@foreach (var item in pro.Models.SiteContentModel.GetMenuContent())
{
switch (((DAL.t_PAGES)(item)).tpage.PAGE_NAME)
{
case "details":
if (((DAL.USER_ACCESS)(item)).tuserAccess.ACC_STATUS == true)
{
<li>@Html.ActionLink("details", "Index", "Business")</li>
}
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.