Linq - How to query specific columns and return a lists

Posted by Billy Logan on Stack Overflow See other posts from Stack Overflow or by Billy Logan
Published on 2010-03-31T15:39:04Z Indexed on 2010/03/31 15:53 UTC
Read the original article Hit count: 501

Filed under:
|

Hello Everyone, I am trying to write a linq query that will only return certain columns from my entity object into a list object.

Below is my code which produces an error(can't implicitly convert a generic list of anonymous types to a generic list of type TBLPROMOTION):

List<TBLPROMOTION> promotionInfo = null;

promotionInfo = (from p in matches
                orderby p.PROMOTION_NM descending
                select new { p.EFFECTIVE_DT, p.EXPIRE_DT, p.IS_ACTIVE, 
                p.PROMOTION_DESC, p.PROMOTION_ID, p.PROMOTION_NM }).ToList();

What would be the best way to accomplish this. I do not want to do a "select p" in this case and return all the columns associated with the query.

thanks in advance, Billy

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-entities