在 linq 中使用 table 加入列表
Join list with table in linq
我有问题。我获取 var 类型变量中的所有数据,然后想在代码优先方法中应用与数据库 table 的连接。遇到问题,网上找了很多申请都没有成功。
var joinedData =
from menuGroup in _menuGroupMenusRepository.GetAll()
.Where(x => x.GroupId == input.GroupId)
join menus in _menuRepository.GetAll()
on menuGroup.MenuId equals menus.Id
join categSubcateg in _menuCategSubCategRepository.GetAll()
on menus.Id equals categSubcateg.MenuId
join categ in _menuCategoryRepository.GetAll()
on categSubcateg.CategoryId equals categ.Id
select new
{
CategoryId = categSubcateg.CategoryId,
CategoryName = categ.Category,
};
现在我想要 joinedData
变量与 MainMenuSort
table 连接。
MainMenuSort table 也有 groupid
和 categoryid
.
要执行连接,您只需按以下步骤操作
var q=(from jd in joinedData
join mms in dataContext.MainMenuSort
on jd.CategoryId equals mms.CategoryId
select jd).ToList();
如果它的数据表那么
var q=(from jd in joinedData
join mms in dtMainMenuSort.AsEnumerable()
on jd.CategoryId equals mms.Field<int>("CategoryId")
select jd).ToList();
我有问题。我获取 var 类型变量中的所有数据,然后想在代码优先方法中应用与数据库 table 的连接。遇到问题,网上找了很多申请都没有成功。
var joinedData =
from menuGroup in _menuGroupMenusRepository.GetAll()
.Where(x => x.GroupId == input.GroupId)
join menus in _menuRepository.GetAll()
on menuGroup.MenuId equals menus.Id
join categSubcateg in _menuCategSubCategRepository.GetAll()
on menus.Id equals categSubcateg.MenuId
join categ in _menuCategoryRepository.GetAll()
on categSubcateg.CategoryId equals categ.Id
select new
{
CategoryId = categSubcateg.CategoryId,
CategoryName = categ.Category,
};
现在我想要 joinedData
变量与 MainMenuSort
table 连接。
MainMenuSort table 也有 groupid
和 categoryid
.
要执行连接,您只需按以下步骤操作
var q=(from jd in joinedData
join mms in dataContext.MainMenuSort
on jd.CategoryId equals mms.CategoryId
select jd).ToList();
如果它的数据表那么
var q=(from jd in joinedData
join mms in dtMainMenuSort.AsEnumerable()
on jd.CategoryId equals mms.Field<int>("CategoryId")
select jd).ToList();