我的查询:
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部分以后,我不知道它是否正在做我想要的,这使我可以访问条件适用的所有三个表上的每一列。
感谢。
答案 0 :(得分:0)
在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
});