LINQ to SQL的加入问题 [英] LINQ to SQL Join issues
问题描述
我尝试使用下面的LINQ在我的代码到SQL:
I'm trying to use the following LINQ to SQL in my code:
(from s in dc.Accounts
join purchases in dc.Transactions on s.AccID equals purchases.Account into pu
join pop in dc.POPTransactions on new { s.ID, syncNo } equals new {AccId = pop.AccountID, SyncNo = pop.SyncNo } into po
where s.AccID == ID && s.Customer == false
select new AccsandPurchase { acc = s, purchases = pu.ToList(), pop = po.ToList() } ));
发生在第二个连接线(在上面整个查询3号线)的错误 - 我用有它,所以它只是加入了s.ID和pop.AccountID和完美的工作,但现在我介绍了另一起critieria(该syncno)我收到以下错误:
The error happens on the second join line (3rd line in the whole query above) - I used to have it so it just joined on s.ID and pop.AccountID and that worked perfect, but now I introduced another join critieria (the syncno) I get the following error:
的类型$ b $表达式b中加入条款之一是不正确。键入
推断在调用
'群组加入失败
"The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'"
任何想法?一些注意事项:
Any ideas? Some notes:
1:'变量'syncNo是一个长期的,因为是在DB(BIGINT)的值。在DB的值可为空,所以我也尝试过多长时间?作为变量类型
1: 'the variable 'syncNo' is a long, as is the value in the DB (bigint). The value in the db is nullable so I've also tried "long?" as the variable type
2:AccsandPurchase是一个自定义类我做了,因为你可能已经猜到
2: AccsandPurchase is a custom class I made, as you can probably guess
谢谢
推荐答案
尽量指定相同的连接键的名字如:
Try to specify the same join key names e.g.
join pop in dc.POPTransactions on new { Key1 = s.ID, Key2 = syncNo } equals new {Key1 = pop.AccountID, Key2 = pop.SyncNo }
这篇关于LINQ to SQL的加入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!