2010-09-14 20 views
0

我会如何得到这样的工作,以便我可以动态地改变这个LINQ中的where子句到sql查询?动态在LINQ到SQL的地方

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) 

与上面的代码我得到这个错误:

后期绑定操作不能转换为表达式树

回答

3

这听起来像你要么没有得到已经选项严格上。穿上它,并指定AccountList的类型为IQueryable(Of Account)。那么你将不会使用后期绑定,并且一切都应该很好。

+0

AccountList只是一个字符串列表,实际上它使IQueryable(的字符串)做了窍门 - 谢谢! – EdenMachine 2010-09-14 17:59:44