Simple Linq Dynamic Query question

Posted by Dr. Zim on Stack Overflow See other posts from Stack Overflow or by Dr. Zim
Published on 2010-03-30T03:23:57Z Indexed on 2010/03/30 3:33 UTC
Read the original article Hit count: 442

Filed under:
|

In Linq Dynamic Query, Scott Guthrie shows an example Linq query:

var query =
    db.Customers.
    Where("City == @0 and Orders.Count >= @1", "London", 10).
    OrderBy("CompanyName").
    Select("new( CompanyName as Name, Phone)");

Notice the projection new( CompanyName as Name, Phone). If I have a class like this:

public class CompanyContact {
    public string Name {get;set;}
    public string Phone {get;set;}
}

How could I essentially "cast" his result using the CompanyContact data type without doing a foreach on each record and dumping it in to a different data structure? To my knowledge the only .Select available is the Dymanic Query version which only takes a string and parameter list.

© Stack Overflow or respective owner

Related posts about dynamicquery

Related posts about LINQ