c# - Wrapping anonymous types in where clauses using linq projection -


i have found myself messing around linq projection , kinda wondering if there possibility take anonymous types , have them wrapped in different types of clauses.

so example:

var projection = (from m in mydata              select new               {                  // wrap around instead of @ end of                  // var projection can have multiple types run differnt                  // linq queries                  serviceselector = new                  {                      // know have where() after each property,                       // rather not have query each 1                      serviceone = m.serviceone,                      servicetwo = m.servicetwo,                      servicethree = m.servicethree                  }                  // end wrap of where() here...              }).firstordefault();              // not have here. since may have other anonymous              // types dont need 

this way can call:

serviceone = projection.serviceselector.serviceone; 

but if call other anonymous type uses groupby() instead this:

groupone = projection.groupselector.groupone; 

i hope provide little bit more knowledge on because think neat use in other situations.


Comments