我的查询:
using (var context = new consoleApp.JohnDoe_dbEntities())
{
var data= (from lo in context.tbl_loans
join doc in context.tbl_docinfo on lo.idDocInfo equals doc.idDocInfo
join insp in context.tbl_inspections on lo.idLoan equals insp.idLoan
where insp.StatusInspections == 3 && lo.idLoan == 5
select new
{
lo,
doc,
insp
});}
我想从tbl_idLoans,tbl_docinfo和tbl_inspections示例访问每个列:“ lo.CityName”。我不明白如何使用LINQ语法访问它们。当前的查询是正确的,除了SELECT部分之后,我不知道它是否在执行我想要的操作,这使我可以访问所有三个有条件的表中的每一列。
谢谢。
最佳答案
在select
语句中为表属性命名。这样,您应该能够使用语法data
,data.FirstOrDefault().Inspection.StatusInspections
等从data.FirstOrDefault().Loan.idLoan
对象的任何表中选择一列。
var data = (from lo in context.tbl_loans
join doc in context.tbl_docinfo on lo.idDocInfo equals doc.idDocInfo
join insp in context.tbl_inspections on lo.idLoan equals insp.idLoan
where insp.StatusInspections == 3 && lo.idLoan == 5
select new
{
Loan = lo,
DocInfo = doc,
Inspection = insp
});