LINQ to SQL 连接问题

LINQ to SQL Join issues(LINQ to SQL 连接问题)
本文介绍了LINQ to SQL 连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在我的代码中使用以下 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 连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Is Unpivot (Not Pivot) functionality available in Linq to SQL? How?(Linq to SQL 中是否提供 Unpivot(非 Pivot)功能?如何?)
How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Linq2SQl eager load with multiple DataLoadOptions(具有多个 DataLoadOptions 的 Linq2SQl 急切加载)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)