Select only a few columns in a LINQ query

I have the following request

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

However, all columns are returned in this case. How to rewrite a query so that only a few columns are returned, e.g. a.CatName, a.CatID, a.CatQty, etc.

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

All Articles