I'm playing around with some Linq-SQL stuff, doing something like this:
var foo = from f in db.Foo where f.Bar > 5 select f;
which is all fine and dandy, and I know I can also do this:
var foo = from f in db.Foo where f.Bar > 5 select new { f.Bar, f.Baz };
What I want to know, is can I factor out the select part of that query, if I want to determine at runtime what parts of Foo to select? Such as:
var foo = from f in db.Foo where f.Bar > 5 select SomeMethodThatReturnsThePropertiesOfFooIReallyWant();
Edit to clarify: I'm looking for the syntax and return type of SomeMethod...().
If I wanted to do this some times:
select new { f.Bar, f.Baz };
but other times do this:
select new { f.Baz, f.Other };
Based on data in memory (without doing a giant case statement), how would i do that, if possible?
Sure, although it's easier in the fluent syntax:
var query_foo = db.Foo.Where(f=>f.Bar > 5);
// :
var foo =query_foo.Select(f=>SomeMethodThatReturnsEtc(f));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With