Linq多表笔记

public IQueryable<E_Admin_Role_Menu> GetRoleMenu()
{
var linq = from role in DB.Admin_Role_Menu
join menu in DB.Admin_Menu
on role.MenuId equals menu.MenuId
join column in DB.Admin_Column
on menu.ColumnId equals column.ColumnId
select new E_Admin_Role_Menu
{
Id = role.Id,
RoleId = role.RoleId,
MenuId = role.MenuId,
E_Admin_Menu = new E_Admin_Menu
{
MenuId = menu.MenuId,
MenuName = menu.MenuName,
HttpUrl = menu.HttpUrl,
ColumnId = menu.ColumnId,
E_Admin_Column = new E_Admin_Column {
ColumnId=column.ColumnId,
ColumnName=column.ColumnName
}
}

};
return linq;
}

 

 

public partial class E_Admin_Role_Menu
{
public int Id { get; set; }
public int RoleId { get; set; }
public int MenuId { get; set; }

public virtual E_Admin_Menu E_Admin_Menu { get; set; }
}

 

 

public partial class E_Admin_Menu
{
public E_Admin_Menu()
{
this.E_Admin_Role_Menu = new HashSet<E_Admin_Role_Menu>();
}

public int MenuId { get; set; }
public string MenuName { get; set; }
public int ColumnId { get; set; }
public string HttpUrl { get; set; }

public virtual E_Admin_Column E_Admin_Column { get; set; }
public virtual ICollection<E_Admin_Role_Menu> E_Admin_Role_Menu { get; set; }
}

posted @ 2012-12-14 10:59  net_miao  阅读(165)  评论(0编辑  收藏  举报