2009-06-04 55 views
0

如果您有自定義類型,並且您希望爲該自定義類型指定List(of T),那麼您如何在vb中這樣做?我發現了一個C#示例如下在LINQ查詢中使用自定義類型

List<myclass> result = (from c in db.Customers where c.orders.count > 1 Select new Myclass 
{ 
Id = c.customerID, 
Name = c.contactname 
}).Tolist(); 

從這個網站http://blogs.msdn.com/swiss_dpe_team/archive/2008/01/25/using-your-own-defined-type-in-a-linq-query-expression.aspx

但我堅持努力讓它在Vb.net工作

回答

3
Dim result = (From c in db.Customers _ 
       Where c.orders.Count > 1 _ 
       Select new Myclass With { _ 
       { 
       .Id = c.customerID, _ 
       .Name = c.contactname _ 
       }).ToList() 
+0

當我這樣做,我得到一個錯誤 不允許在查詢中顯式構造實體類型'Myclass'。 這篇文章http://stackoverflow.com/questions/787296/explicit-construction-of-entity-type-in​​-query-is-not-allowed說這是不允許的 – 2009-06-04 15:12:30