我有列表對象,我需要在VB.NET使用LINQ逗號分隔字符串來查身份證,這樣的事情:LINQ過濾對象列表
dim strId as String = "1,2,3,5,"
dim myList = from objmylist where objmylist.id in (strId)
我有列表對象,我需要在VB.NET使用LINQ逗號分隔字符串來查身份證,這樣的事情:LINQ過濾對象列表
dim strId as String = "1,2,3,5,"
dim myList = from objmylist where objmylist.id in (strId)
dim strId as String = "1,2,3,5,"
dim IDs as String() = strId.Split(",")
dim myList = from objmylist where IDs.Contains(objmylist.id)
select objmylist
dim strId as String = "1,2,3,5,"
dim myList = from objmylist where strId.split(",").Contains(objmylist.id)
未經測試,但應該做的伎倆我猜。
你的代碼是完全正常的,如果你在LINQ 使用它在C#中,你會做到這一點之前分割字符串:
string strIDs = "1,2,3,5,";
string[] arrIDs = strIDs.Split(",");
var myList = objmylist.Where(o => arrIDs.Contains(o.id));
也許你能理解這一點足以把它翻譯成VB
使用C#,
int[] productList = new int[] { 1, 2, 3, 4 };
var myProducts = from p in db.Products
where productList.Contains(p.ProductID)
select p;
使用VB.NET,
Dim productList As Integer() = New Integer() {1, 2, 3, 4}
Dim myProducts = From p In db.Products Where productList.Contains(p.ProductID)
+1燁參考這就是我想說的,但我的VB是生鏽:) – Bazzz 2011-03-01 12:45:25