问题描述
我正在尝试在我的代码中使用以下 LINQ to 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 上连接,效果很好,但现在我引入了另一个连接标准(同步)我收到以下错误:
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:
"中的表达式之一的类型join 子句不正确.类型调用中的推理失败'GroupJoin'"
"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' 是一个长整数,与数据库中的值 (bigint) 一样.数据库中的值可以为空,所以我也试过长?"作为变量类型
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 连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!