Jeju
Jeju

Reputation: 53

Select only few columns in LINQ query

I have the following query

 var xyz = from a in prod.Categories
                           where a.CatName.EndsWith("A")
                           select a;

However all the columns are returned in this case. How do i rewrite query so that only few columns are returned like a.CatName, a.CatID, a.CatQty and so on.

Upvotes: 5

Views: 11561

Answers (2)

Coding Flow
Coding Flow

Reputation: 21881

var xyz = from a in prod.Categories
                           where a.CatName.EndsWith("A")
                           select new { CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty};

Upvotes: 6

Julian de Wit
Julian de Wit

Reputation: 3094

 var xyz = from a in prod.Categories
                           where a.CatName.EndsWith("A")
                           select new { a.CatID,a.CatQty } ;

Upvotes: 4

Related Questions