Linq加入声明 [英] Linq join statement
本文介绍了Linq加入声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从实体模型的多个表中进行选择.但是我想选择两列,但没有解决.我的LINQ语句是:
I am trying to select from multiple tables in an entity model. But there are two columns I would like to select and it's just not working out. The LINQ statement I have is:
var searchResult = from i in _imEntities.Issues
join dept in _imEntities.Departments
on i.Issued_to_dept equals dept.Dept_ID
where i.State == 1
select new {
i.ID_No,
i.Issue_Date,
Raised_By = dept.Dept_Name
.Where(i.Raised_by_Dept == dept.Dept_ID),
Issued_To = dept.Dept_Name
.Where(i.Issued_to_dept == dept.Dept_ID),
Details = i.Details
};
列名称都是正确的,但是我无法将dept_Names放入Raised_By和Issued_To字段中.还有另一种方法可以执行此操作吗?
The column names are all correct, but I just can't get the dept_Names into the Raised_By and Issued_To fields. Is there another way to execute this?
推荐答案
尝试一下:
var query = from i in _imEntities.Issues
join dept_r in _imEntities.Departments
on i.Issued_to_dept equals dept_r.Dept_ID
join dept_i in _imEntities.Departments
on i.Issued_to_dept equals dept_i.Dept_ID
where i.State == 1
select new {
i.ID_No,
i.Issue_Date,
Raised_By = dept_r.Dept_Name,
Issued_To = dept_i.Dept_Name,
Details = i.Details
};
这篇关于Linq加入声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文