tags:

views:

66

answers:

1

If you have custom type, and you wish to assign a List(of T) to that custom type, how do you do so in vb? I found a C# example as below

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

From this site http://blogs.msdn.com/swiss_dpe_team/archive/2008/01/25/using-your-own-defined-type-in-a-linq-query-expression.aspx

But I am stuck trying to get it to work in Vb.net

+3  A: 
Dim result = (From c in db.Customers _ 
              Where c.orders.Count > 1 _
              Select new Myclass With { _
              {
                 .Id = c.customerID, _
                 .Name = c.contactname _
              }).ToList()
Mehrdad Afshari
When I do this, I get an errorExplicit construction of entity type 'Myclass' in query is not allowed.This post http://stackoverflow.com/questions/787296/explicit-construction-of-entity-type-in-query-is-not-allowed Says that this is'nt allowed
Aaron M
That's not an issue with LINQ, but LINQ to SQL. MyClass is an entity type. You should create a separate class, manually, for that.
Mehrdad Afshari
Also, be aware that 'MyClass' is a reserved word in VB.Net, so if you're using MyClass in real code, that might cause a problem.
Chris Dunaway
@Chris: Great point.
Mehrdad Afshari