【发布时间】:2012-06-01 20:33:15
【问题描述】:
我将如何在 LINQ 中执行此操作?
SQL
Where tblAccounts.AccountCode = tblAccountAssociations.ChildCode
And tblAccountAssociations.AssociationType = "DS"
这是我的尝试。问题似乎出在“assoc.AssociationType == "DS"。它是联接的一部分还是 Where 子句的一部分?
var customers =
from customer in context.tblAccounts
join assoc in context.tblAccountAssociations on customer.AccountCode equals assoc.ChildCode
where customer.AccountType == "S" and assoc.AssociationType == "DS"
orderby customer.AccountType
select new { Customer = customer, Assoc = assoc };
提前致谢
【问题讨论】:
-
您需要添加更多代码。您的 SQL 没有显示完整的查询,并且您的 LINQ 没有显示您正在查询的集合或类型。例如;什么是“关联”?
-
vcsjones - 我没有使用 tablea 中的 col1、col2 到 tableb 中的 col1、col2。我的条件之一是硬编码值,即“DS”
-
你现在所拥有的东西不能用吗?看起来应该没问题。
-
CAbbott - 这不起作用。除其他外,它说“查询主体必须以 select 子句或 group 子句结尾。
标签: c# linq inner-join multiple-tables