我有有效查询(在.Net4.0中)获取仍然开放的发票:
Dim dinvs = AcStudentInvoiceDetails _
.GroupBy(Function(di) di.InvoiceID) _
.Select(Function(di2) New With { _
.InvoiceID = di2.Key, _
.DebitSum = di2.Sum(Function(di3) di3.Debit), _
.CreditSum = di2.Sum(Function(di3) di3.Credit) }) _
.Where(Function(dd) dd.DebitSum > dd.CreditSum)
Dim invs = From i In AcStudentInvoices _
Join di In dinvs On i.ID Equals di.InvoiceID _
Select i
我在LinqPad上测试了这个查询,它得到了正确的结果,但LinqPad在.Net 4.0上运行,我的项目在.Net3.5上运行,错误是我们有一个匿名对象,在.Net3.5中, Where
无法使用匿名对象。
我尝试创建一个强类型的类而不是匿名对象但是我迷失了Linq的语法,所以我需要在.Net3.5中使用这个查询的等价物
错误文字摘录:
重载解析失败,因为无法使用这些参数调用可访问的“Where”:
扩展方法'Public Function Where(谓词As System.Linq.Expressions.Expression(Of System.Func(Of< anonymous type>,Integer,Boolean)))As System.Linq.IQueryable(Of< anonymous type&gt ;''在'System.Linq.Queryable'中定义:嵌套函数与委托'System.Func(Of< anonymous type>,Integer,Boolean)'没有相同的签名'...
答案 0 :(得分:1)
您应该可以使用强类型
来执行此操作Public Class ST
Public Property InvoiceID As String
Public Property DebitSum As Double
Public Property CrediSum As Double
End Class
使您的查询成为这样,
Dim dinvs = AcStudentInvoiceDetails
.GroupBy(Function(di) di.InvoiceID)
.Select(Function(di2) New ST With {
.InvoiceID = di2.Key,
.DebitSum = di2.Sum(Function(di3) di3.Debit),
.CreditSum = di2.Sum(Function(di3) di3.Credit) })
.Where(Function(dd As ST) dd.DebitSum > dd.CreditSum)
Dim invs = From i In AcStudentInvoices
Join di In dinvs On i.ID Equals di.InvoiceID
Select i