c# - Linq: Filter by calculation result and reuse this result -


i have collection (in dbset) want sort calculation result of property (distance) , transform (re-using distance) different model. calculation should happen once per entry (and dbset, it'll executed in db itself).

class inputmodel {     vector3 position; }  class outputmodel {     double distance; }  var inputlist = getinputlist(); // returns iqueryable<inputmodel>  var outputlist = inputlist .where( x => (){     var dist = calculatedistance( x.position );     // calculatedistance() boils down simple equation directly translated sql-query (when typed in statically hand)     return dist < maxdistance; }) .select( x => () {     return new outputmodel {         distance = ???; // calculated distance somehow }) .tolist(); 

two possible solutions come mind:

  1. get entries out of database container , calculate distance , filter entries out in foreach-loop.
  2. filter distance , recalculate distance when transforming outputmodel.

is possible in 1 go (preferred calculation in db itself)?

you can inputlist.where(....).select(x=>calculatedistance).select(dist=> new outputmodel)... commenting mobile cannot type out full statement. should point in right direction. basically. fist select distance. select output model


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -