Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all columns on an object with Linq

Tags:

I have a query:

var transactions = from t in db.Transactions                         where t.SellingPrice != 0                          select new { t.CommissionPercent, t.SellingPrice }; 

But in reality, I need to avoid using an anonymous type because it is readonly and select all the properties/columns on my "transaction" item.

I would have thought that it would be something like this:

var transactions = from t in db.Transactions                         where t.SellingPrice != 0                          select t.SellingPrice, t.CommissionPercent, t.Etc... 

Or...

var transactions = from t in db.Transactions                         where t.SellingPrice != 0                          select t.SellingPrice                         select t.CommissionPercent                         select t.Etc... 

Is there no way to retrieve everything the object has for properties and pass it to the Ienumerable?

like image 437
Isaiah Nelson Avatar asked Feb 01 '12 21:02

Isaiah Nelson


1 Answers

If you want to avoid anonymous types and get everything, why not just return an IEnumerable of the original transaction item?

var transactions = from t in db.Transactions                         where t.SellingPrice != 0                          select t; 
like image 138
Steve Danner Avatar answered Sep 20 '22 10:09

Steve Danner