Linq to SQL 中的动态Where
我怎样才能让这样的东西工作,以便我可以动态地改变这个 linq to sql 查询中的 where 子句?
Dim AccountID = 1234
Dim AccountList
Select Case Types
Case 1
AccountList = (from a in dc.Accounts where a.ID = AccountID)
Case 2
AccountList = (from a in dc.Accounts where a.ID = AccountID And a.ParentID = AccountID)
Case Else
AccountList = (from a in dc.Accounts)
End Select
Return From p in dc.Products where AccountList.Contains(p.Order.Transaction.AccountID)
使用上面的代码,我收到此错误:
后期绑定操作无法转换为表达式树
How would I get something like this to work so that I can dynamically alter the where-clause in this linq to sql query?
Dim AccountID = 1234
Dim AccountList
Select Case Types
Case 1
AccountList = (from a in dc.Accounts where a.ID = AccountID)
Case 2
AccountList = (from a in dc.Accounts where a.ID = AccountID And a.ParentID = AccountID)
Case Else
AccountList = (from a in dc.Accounts)
End Select
Return From p in dc.Products where AccountList.Contains(p.Order.Transaction.AccountID)
With the above code I get this error:
Late binding operations cannot be converted to an expression tree
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您要么没有启用 Option Strict。戴上它,并将
AccountList
的类型指定为IQueryable(Of Account)
。那么你就不会使用后期绑定,一切都应该很好。It sounds like you've either not got Option Strict on. Put it on, and specify the type of
AccountList
asIQueryable(Of Account)
. Then you won't be using late binding, and all should be well.