Search code examples
c#vb.netlinqnpoco

Linq query translation for Npoco: c# to vb.net


What I am trying to do is: retrieving only certain fields from the model when querying a database with the NPoco ORM.

I am forced to do it in vb.net, and I want to use linq to make the code cleaner (instead of a hard-coded string, which would be my last resort).

I have found the linq query in c# here (see @schotime [owner] first answer). So this is the linq query I want to translate:

db.FetchBy<User>(sql => sql.Select(x=> new { x.Id, x.Name }));

...which the Telerik c# to vb.net translator translates as:

db.FetchBy(Of User)(Function(sql) sql.[Select](Function(x) New From { x.Id, x.Name }))

This seems off (the From keyword gives an error) and none of the alternatives that I tried by myself have worked either.

Any ideas?...


Solution

  • I think you're looking for (anonymous type):

    db.FetchBy(Of User)(Function(sql) sql.Select(Function(x) New With {x.Id, x.Name}))