开发者

Dynamic Where in Linq to SQL

开发者 https://www.devze.com 2023-01-16 16:22 出处:网络
How would I get something like this to work so that I can dynamically alter the where-clause in this linq to sql query?

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
开发者_如何学C    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


It sounds like you've either not got Option Strict on. Put it on, and specify the type of AccountList as IQueryable(Of Account). Then you won't be using late binding, and all should be well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号