MongoQueryable.cs 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825
  1. /* Copyright 2015-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Linq.Expressions;
  19. using System.Reflection;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. namespace MongoDB.Driver.Linq
  23. {
  24. /// <summary>
  25. /// Extension for <see cref="IMongoQueryable" />.
  26. /// </summary>
  27. public static class MongoQueryable
  28. {
  29. /// <summary>
  30. /// Determines whether a sequence contains any elements.
  31. /// </summary>
  32. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  33. /// <param name="source">A sequence to check for being empty.</param>
  34. /// <param name="cancellationToken">The cancellation token.</param>
  35. /// <returns>
  36. /// true if the source sequence contains any elements; otherwise, false.
  37. /// </returns>
  38. public static Task<bool> AnyAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  39. {
  40. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<bool>(
  41. Expression.Call(
  42. GetMethodInfo<IQueryable<TSource>, bool>(Queryable.Any, source),
  43. source.Expression),
  44. cancellationToken);
  45. }
  46. /// <summary>
  47. /// Determines whether any element of a sequence satisfies a condition.
  48. /// </summary>
  49. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  50. /// <param name="source">A sequence whose elements to test for a condition.</param>
  51. /// <param name="predicate">A function to test each element for a condition.</param>
  52. /// <param name="cancellationToken">The cancellation token.</param>
  53. /// <returns>
  54. /// true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.
  55. /// </returns>
  56. public static Task<bool> AnyAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  57. {
  58. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<bool>(
  59. Expression.Call(
  60. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, bool>(Queryable.Any, source, predicate),
  61. source.Expression,
  62. Expression.Quote(predicate)),
  63. cancellationToken);
  64. }
  65. /// <summary>
  66. /// Computes the average of a sequence of <see cref="Decimal"/> values.
  67. /// </summary>
  68. /// <param name="source">A sequence of values to calculate the average of.</param>
  69. /// <param name="cancellationToken">The cancellation token.</param>
  70. /// <returns>The average of the values in the sequence.</returns>
  71. public static Task<decimal> AverageAsync(this IMongoQueryable<decimal> source, CancellationToken cancellationToken = default(CancellationToken))
  72. {
  73. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  74. Expression.Call(
  75. GetMethodInfo<IQueryable<decimal>, decimal>(Queryable.Average, source),
  76. source.Expression),
  77. cancellationToken);
  78. }
  79. /// <summary>
  80. /// Computes the average of a sequence of <see cref="Nullable{Decimal}"/> values.
  81. /// </summary>
  82. /// <param name="source">A sequence of values to calculate the average of.</param>
  83. /// <param name="cancellationToken">The cancellation token.</param>
  84. /// <returns>The average of the values in the sequence.</returns>
  85. public static Task<decimal?> AverageAsync(this IMongoQueryable<decimal?> source, CancellationToken cancellationToken = default(CancellationToken))
  86. {
  87. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  88. Expression.Call(
  89. GetMethodInfo<IQueryable<decimal?>, decimal?>(Queryable.Average, source),
  90. source.Expression),
  91. cancellationToken);
  92. }
  93. /// <summary>
  94. /// Computes the average of a sequence of <see cref="Double"/> values.
  95. /// </summary>
  96. /// <param name="source">A sequence of values to calculate the average of.</param>
  97. /// <param name="cancellationToken">The cancellation token.</param>
  98. /// <returns>The average of the values in the sequence.</returns>
  99. public static Task<double> AverageAsync(this IMongoQueryable<double> source, CancellationToken cancellationToken = default(CancellationToken))
  100. {
  101. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  102. Expression.Call(
  103. GetMethodInfo<IQueryable<double>, double>(Queryable.Average, source),
  104. source.Expression),
  105. cancellationToken);
  106. }
  107. /// <summary>
  108. /// Computes the average of a sequence of <see cref="Nullable{Double}"/> values.
  109. /// </summary>
  110. /// <param name="source">A sequence of values to calculate the average of.</param>
  111. /// <param name="cancellationToken">The cancellation token.</param>
  112. /// <returns>The average of the values in the sequence.</returns>
  113. public static Task<double?> AverageAsync(this IMongoQueryable<double?> source, CancellationToken cancellationToken = default(CancellationToken))
  114. {
  115. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  116. Expression.Call(
  117. GetMethodInfo<IQueryable<double?>, double?>(Queryable.Average, source),
  118. source.Expression),
  119. cancellationToken);
  120. }
  121. /// <summary>
  122. /// Computes the average of a sequence of <see cref="Single"/> values.
  123. /// </summary>
  124. /// <param name="source">A sequence of values to calculate the average of.</param>
  125. /// <param name="cancellationToken">The cancellation token.</param>
  126. /// <returns>The average of the values in the sequence.</returns>
  127. public static Task<float> AverageAsync(this IMongoQueryable<float> source, CancellationToken cancellationToken = default(CancellationToken))
  128. {
  129. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  130. Expression.Call(
  131. GetMethodInfo<IQueryable<float>, float>(Queryable.Average, source),
  132. source.Expression),
  133. cancellationToken);
  134. }
  135. /// <summary>
  136. /// Computes the average of a sequence of <see cref="Nullable{Single}"/> values.
  137. /// </summary>
  138. /// <param name="source">A sequence of values to calculate the average of.</param>
  139. /// <param name="cancellationToken">The cancellation token.</param>
  140. /// <returns>The average of the values in the sequence.</returns>
  141. public static Task<float?> AverageAsync(this IMongoQueryable<float?> source, CancellationToken cancellationToken = default(CancellationToken))
  142. {
  143. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  144. Expression.Call(
  145. GetMethodInfo<IQueryable<float?>, float?>(Queryable.Average, source),
  146. source.Expression),
  147. cancellationToken);
  148. }
  149. /// <summary>
  150. /// Computes the average of a sequence of <see cref="Int32"/> values.
  151. /// </summary>
  152. /// <param name="source">A sequence of values to calculate the average of.</param>
  153. /// <param name="cancellationToken">The cancellation token.</param>
  154. /// <returns>The average of the values in the sequence.</returns>
  155. public static Task<double> AverageAsync(this IMongoQueryable<int> source, CancellationToken cancellationToken = default(CancellationToken))
  156. {
  157. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  158. Expression.Call(
  159. GetMethodInfo<IQueryable<int>, double>(Queryable.Average, source),
  160. source.Expression),
  161. cancellationToken);
  162. }
  163. /// <summary>
  164. /// Computes the average of a sequence of <see cref="Nullable{Int32}"/> values.
  165. /// </summary>
  166. /// <param name="source">A sequence of values to calculate the average of.</param>
  167. /// <param name="cancellationToken">The cancellation token.</param>
  168. /// <returns>The average of the values in the sequence.</returns>
  169. public static Task<double?> AverageAsync(this IMongoQueryable<int?> source, CancellationToken cancellationToken = default(CancellationToken))
  170. {
  171. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  172. Expression.Call(
  173. GetMethodInfo<IQueryable<int?>, double?>(Queryable.Average, source),
  174. source.Expression),
  175. cancellationToken);
  176. }
  177. /// <summary>
  178. /// Computes the average of a sequence of <see cref="Int64"/> values.
  179. /// </summary>
  180. /// <param name="source">A sequence of values to calculate the average of.</param>
  181. /// <param name="cancellationToken">The cancellation token.</param>
  182. /// <returns>The average of the values in the sequence.</returns>
  183. public static Task<double> AverageAsync(this IMongoQueryable<long> source, CancellationToken cancellationToken = default(CancellationToken))
  184. {
  185. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  186. Expression.Call(
  187. GetMethodInfo<IQueryable<long>, double>(Queryable.Average, source),
  188. source.Expression),
  189. cancellationToken);
  190. }
  191. /// <summary>
  192. /// Computes the average of a sequence of <see cref="Nullable{Int64}"/> values.
  193. /// </summary>
  194. /// <param name="source">A sequence of values to calculate the average of.</param>
  195. /// <param name="cancellationToken">The cancellation token.</param>
  196. /// <returns>The average of the values in the sequence.</returns>
  197. public static Task<double?> AverageAsync(this IMongoQueryable<long?> source, CancellationToken cancellationToken = default(CancellationToken))
  198. {
  199. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  200. Expression.Call(
  201. GetMethodInfo<IQueryable<long?>, double?>(Queryable.Average, source),
  202. source.Expression),
  203. cancellationToken);
  204. }
  205. /// <summary>
  206. /// Computes the average of the sequence of <see cref="Decimal" /> values that is obtained
  207. /// by invoking a projection function on each element of the input sequence.
  208. /// </summary>
  209. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  210. /// <param name="source">A sequence of values.</param>
  211. /// <param name="selector">A projection function to apply to each element.</param>
  212. /// <param name="cancellationToken">The cancellation token.</param>
  213. /// <returns>
  214. /// The average of the projected values.
  215. /// </returns>
  216. public static Task<decimal> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default(CancellationToken))
  217. {
  218. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  219. Expression.Call(
  220. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, decimal>>, decimal>(Queryable.Average, source, selector),
  221. source.Expression,
  222. Expression.Quote(selector)),
  223. cancellationToken);
  224. }
  225. /// <summary>
  226. /// Computes the average of the sequence of <see cref="Nullable{Decimal}" /> values that is obtained
  227. /// by invoking a projection function on each element of the input sequence.
  228. /// </summary>
  229. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  230. /// <param name="source">A sequence of values.</param>
  231. /// <param name="selector">A projection function to apply to each element.</param>
  232. /// <param name="cancellationToken">The cancellation token.</param>
  233. /// <returns>
  234. /// The average of the projected values.
  235. /// </returns>
  236. public static Task<decimal?> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  237. {
  238. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  239. Expression.Call(
  240. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, decimal?>>, decimal?>(Queryable.Average, source, selector),
  241. source.Expression,
  242. Expression.Quote(selector)),
  243. cancellationToken);
  244. }
  245. /// <summary>
  246. /// Computes the average of the sequence of <see cref="Double" /> values that is obtained
  247. /// by invoking a projection function on each element of the input sequence.
  248. /// </summary>
  249. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  250. /// <param name="source">A sequence of values.</param>
  251. /// <param name="selector">A projection function to apply to each element.</param>
  252. /// <param name="cancellationToken">The cancellation token.</param>
  253. /// <returns>
  254. /// The average of the projected values.
  255. /// </returns>
  256. public static Task<double> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default(CancellationToken))
  257. {
  258. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  259. Expression.Call(
  260. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, double>>, double>(Queryable.Average, source, selector),
  261. source.Expression,
  262. Expression.Quote(selector)),
  263. cancellationToken);
  264. }
  265. /// <summary>
  266. /// Computes the average of the sequence of <see cref="Nullable{Double}" /> values that is obtained
  267. /// by invoking a projection function on each element of the input sequence.
  268. /// </summary>
  269. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  270. /// <param name="source">A sequence of values.</param>
  271. /// <param name="selector">A projection function to apply to each element.</param>
  272. /// <param name="cancellationToken">The cancellation token.</param>
  273. /// <returns>
  274. /// The average of the projected values.
  275. /// </returns>
  276. public static Task<double?> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  277. {
  278. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  279. Expression.Call(
  280. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, double?>>, double?>(Queryable.Average, source, selector),
  281. source.Expression,
  282. Expression.Quote(selector)),
  283. cancellationToken);
  284. }
  285. /// <summary>
  286. /// Computes the average of the sequence of <see cref="Single" /> values that is obtained
  287. /// by invoking a projection function on each element of the input sequence.
  288. /// </summary>
  289. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  290. /// <param name="source">A sequence of values.</param>
  291. /// <param name="selector">A projection function to apply to each element.</param>
  292. /// <param name="cancellationToken">The cancellation token.</param>
  293. /// <returns>
  294. /// The average of the projected values.
  295. /// </returns>
  296. public static Task<float> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default(CancellationToken))
  297. {
  298. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  299. Expression.Call(
  300. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, float>>, float>(Queryable.Average, source, selector),
  301. source.Expression,
  302. Expression.Quote(selector)),
  303. cancellationToken);
  304. }
  305. /// <summary>
  306. /// Computes the average of the sequence of <see cref="Nullable{Single}" /> values that is obtained
  307. /// by invoking a projection function on each element of the input sequence.
  308. /// </summary>
  309. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  310. /// <param name="source">A sequence of values.</param>
  311. /// <param name="selector">A projection function to apply to each element.</param>
  312. /// <param name="cancellationToken">The cancellation token.</param>
  313. /// <returns>
  314. /// The average of the projected values.
  315. /// </returns>
  316. public static Task<float?> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  317. {
  318. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  319. Expression.Call(
  320. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, float?>>, float?>(Queryable.Average, source, selector),
  321. source.Expression,
  322. Expression.Quote(selector)),
  323. cancellationToken);
  324. }
  325. /// <summary>
  326. /// Computes the average of the sequence of <see cref="Int32" /> values that is obtained
  327. /// by invoking a projection function on each element of the input sequence.
  328. /// </summary>
  329. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  330. /// <param name="source">A sequence of values.</param>
  331. /// <param name="selector">A projection function to apply to each element.</param>
  332. /// <param name="cancellationToken">The cancellation token.</param>
  333. /// <returns>
  334. /// The average of the projected values.
  335. /// </returns>
  336. public static Task<double> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default(CancellationToken))
  337. {
  338. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  339. Expression.Call(
  340. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, int>>, double>(Queryable.Average, source, selector),
  341. source.Expression,
  342. Expression.Quote(selector)),
  343. cancellationToken);
  344. }
  345. /// <summary>
  346. /// Computes the average of the sequence of <see cref="Nullable{Int32}" /> values that is obtained
  347. /// by invoking a projection function on each element of the input sequence.
  348. /// </summary>
  349. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  350. /// <param name="source">A sequence of values.</param>
  351. /// <param name="selector">A projection function to apply to each element.</param>
  352. /// <param name="cancellationToken">The cancellation token.</param>
  353. /// <returns>
  354. /// The average of the projected values.
  355. /// </returns>
  356. public static Task<double?> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  357. {
  358. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  359. Expression.Call(
  360. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, int?>>, double?>(Queryable.Average, source, selector),
  361. source.Expression,
  362. Expression.Quote(selector)),
  363. cancellationToken);
  364. }
  365. /// <summary>
  366. /// Computes the average of the sequence of <see cref="Int64" /> values that is obtained
  367. /// by invoking a projection function on each element of the input sequence.
  368. /// </summary>
  369. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  370. /// <param name="source">A sequence of values.</param>
  371. /// <param name="selector">A projection function to apply to each element.</param>
  372. /// <param name="cancellationToken">The cancellation token.</param>
  373. /// <returns>
  374. /// The average of the projected values.
  375. /// </returns>
  376. public static Task<double> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default(CancellationToken))
  377. {
  378. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  379. Expression.Call(
  380. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, long>>, double>(Queryable.Average, source, selector),
  381. source.Expression,
  382. Expression.Quote(selector)),
  383. cancellationToken);
  384. }
  385. /// <summary>
  386. /// Computes the average of the sequence of <see cref="Nullable{Int64}" /> values that is obtained
  387. /// by invoking a projection function on each element of the input sequence.
  388. /// </summary>
  389. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  390. /// <param name="source">A sequence of values.</param>
  391. /// <param name="selector">A projection function to apply to each element.</param>
  392. /// <param name="cancellationToken">The cancellation token.</param>
  393. /// <returns>
  394. /// The average of the projected values.
  395. /// </returns>
  396. public static Task<double?> AverageAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  397. {
  398. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  399. Expression.Call(
  400. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, long?>>, double?>(Queryable.Average, source, selector),
  401. source.Expression,
  402. Expression.Quote(selector)),
  403. cancellationToken);
  404. }
  405. /// <summary>
  406. /// Returns the number of elements in a sequence.
  407. /// </summary>
  408. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  409. /// <param name="source">The <see cref="IMongoQueryable{TSource}" /> that contains the elements to be counted.</param>
  410. /// <param name="cancellationToken">The cancellation token.</param>
  411. /// <returns>
  412. /// The number of elements in the input sequence.
  413. /// </returns>
  414. public static Task<int> CountAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  415. {
  416. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int>(
  417. Expression.Call(
  418. GetMethodInfo<IQueryable<TSource>, int>(Queryable.Count, source),
  419. source.Expression),
  420. cancellationToken);
  421. }
  422. /// <summary>
  423. /// Returns the number of elements in the specified sequence that satisfies a condition.
  424. /// </summary>
  425. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  426. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> that contains the elements to be counted.</param>
  427. /// <param name="predicate">A function to test each element for a condition.</param>
  428. /// <param name="cancellationToken">The cancellation token.</param>
  429. /// <returns>
  430. /// The number of elements in the sequence that satisfies the condition in the predicate function.
  431. /// </returns>
  432. public static Task<int> CountAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  433. {
  434. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int>(
  435. Expression.Call(
  436. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, int>(Queryable.Count, source, predicate),
  437. source.Expression,
  438. Expression.Quote(predicate)),
  439. cancellationToken);
  440. }
  441. /// <summary>
  442. /// Returns distinct elements from a sequence by using the default equality comparer to compare values.
  443. /// </summary>
  444. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  445. /// <param name="source">The <see cref="IMongoQueryable{TSource}" /> to remove duplicates from.</param>
  446. /// <returns>
  447. /// An <see cref="IMongoQueryable{TSource}" /> that contains distinct elements from <paramref name="source" />.
  448. /// </returns>
  449. public static IMongoQueryable<TSource> Distinct<TSource>(this IMongoQueryable<TSource> source)
  450. {
  451. return (IMongoQueryable<TSource>)Queryable.Distinct(source);
  452. }
  453. /// <summary>
  454. /// Returns the first element of a sequence.
  455. /// </summary>
  456. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  457. /// <param name="source">The <see cref="IMongoQueryable{TSource}" /> to return the first element of.</param>
  458. /// <param name="cancellationToken">The cancellation token.</param>
  459. /// <returns>
  460. /// The first element in <paramref name="source" />.
  461. /// </returns>
  462. public static Task<TSource> FirstAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  463. {
  464. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  465. Expression.Call(
  466. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.First, source),
  467. source.Expression),
  468. cancellationToken);
  469. }
  470. /// <summary>
  471. /// Returns the first element of a sequence that satisfies a specified condition.
  472. /// </summary>
  473. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  474. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return an element from.</param>
  475. /// <param name="predicate">A function to test each element for a condition.</param>
  476. /// <param name="cancellationToken">The cancellation token.</param>
  477. /// <returns>
  478. /// The first element in <paramref name="source" /> that passes the test in <paramref name="predicate" />.
  479. /// </returns>
  480. public static Task<TSource> FirstAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  481. {
  482. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  483. Expression.Call(
  484. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, TSource>(Queryable.First, source, predicate),
  485. source.Expression,
  486. Expression.Quote(predicate)),
  487. cancellationToken);
  488. }
  489. /// <summary>
  490. /// Returns the first element of a sequence, or a default value if the sequence contains no elements.
  491. /// </summary>
  492. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  493. /// <param name="source">The <see cref="IMongoQueryable{TSource}" /> to return the first element of.</param>
  494. /// <param name="cancellationToken">The cancellation token.</param>
  495. /// <returns>
  496. /// default(<typeparamref name="TSource" />) if <paramref name="source" /> is empty; otherwise, the first element in <paramref name="source" />.
  497. /// </returns>
  498. public static Task<TSource> FirstOrDefaultAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  499. {
  500. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  501. Expression.Call(
  502. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.FirstOrDefault, source),
  503. source.Expression),
  504. cancellationToken);
  505. }
  506. /// <summary>
  507. /// Returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.
  508. /// </summary>
  509. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  510. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return an element from.</param>
  511. /// <param name="predicate">A function to test each element for a condition.</param>
  512. /// <param name="cancellationToken">The cancellation token.</param>
  513. /// <returns>
  514. /// default(<typeparamref name="TSource" />) if <paramref name="source" /> is empty or if no element passes the test specified by <paramref name="predicate" />; otherwise, the first element in <paramref name="source" /> that passes the test specified by <paramref name="predicate" />.
  515. /// </returns>
  516. public static Task<TSource> FirstOrDefaultAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  517. {
  518. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  519. Expression.Call(
  520. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, TSource>(Queryable.FirstOrDefault, source, predicate),
  521. source.Expression,
  522. Expression.Quote(predicate)),
  523. cancellationToken);
  524. }
  525. /// <summary>
  526. /// Groups the elements of a sequence according to a specified key selector function.
  527. /// </summary>
  528. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  529. /// <typeparam name="TKey">The type of the key returned by the function represented in keySelector.</typeparam>
  530. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> whose elements to group.</param>
  531. /// <param name="keySelector">A function to extract the key for each element.</param>
  532. /// <returns>
  533. /// An <see cref="IMongoQueryable{T}" /> that has a type argument of <see cref="IGrouping{TKey, TSource}"/>
  534. /// and where each <see cref="IGrouping{TKey, TSource}"/> object contains a sequence of objects
  535. /// and a key.
  536. /// </returns>
  537. public static IMongoQueryable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  538. {
  539. return (IMongoQueryable<IGrouping<TKey, TSource>>)Queryable.GroupBy(source, keySelector);
  540. }
  541. /// <summary>
  542. /// Groups the elements of a sequence according to a specified key selector function
  543. /// and creates a result value from each group and its key.
  544. /// </summary>
  545. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  546. /// <typeparam name="TKey">The type of the key returned by the function represented in keySelector.</typeparam>
  547. /// <typeparam name="TResult">The type of the result value returned by resultSelector.</typeparam>
  548. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> whose elements to group.</param>
  549. /// <param name="keySelector">A function to extract the key for each element.</param>
  550. /// <param name="resultSelector">A function to create a result value from each group.</param>
  551. /// <returns>
  552. /// An <see cref="IMongoQueryable{T}" /> that has a type argument of TResult and where
  553. /// each element represents a projection over a group and its key.
  554. /// </returns>
  555. public static IMongoQueryable<TResult> GroupBy<TSource, TKey, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TKey, IEnumerable<TSource>, TResult>> resultSelector)
  556. {
  557. return (IMongoQueryable<TResult>)Queryable.GroupBy(source, keySelector, resultSelector);
  558. }
  559. /// <summary>
  560. /// Correlates the elements of two sequences based on key equality and groups the results.
  561. /// </summary>
  562. /// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
  563. /// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
  564. /// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
  565. /// <typeparam name="TResult">The type of the result elements.</typeparam>
  566. /// <param name="outer">The first sequence to join.</param>
  567. /// <param name="inner">The sequence to join to the first sequence.</param>
  568. /// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
  569. /// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
  570. /// <param name="resultSelector">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
  571. /// <returns>
  572. /// An <see cref="IMongoQueryable{TResult}" /> that contains elements of type <typeparamref name="TResult" /> obtained by performing a grouped join on two sequences.
  573. /// </returns>
  574. public static IMongoQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IMongoQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector)
  575. {
  576. return (IMongoQueryable<TResult>)Queryable.GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector);
  577. }
  578. /// <summary>
  579. /// Correlates the elements of two sequences based on key equality and groups the results.
  580. /// </summary>
  581. /// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
  582. /// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
  583. /// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
  584. /// <typeparam name="TResult">The type of the result elements.</typeparam>
  585. /// <param name="outer">The first sequence to join.</param>
  586. /// <param name="inner">The collection to join to the first sequence.</param>
  587. /// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
  588. /// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
  589. /// <param name="resultSelector">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
  590. /// <returns>
  591. /// An <see cref="IMongoQueryable{TResult}" /> that contains elements of type <typeparamref name="TResult" /> obtained by performing a grouped join on two sequences.
  592. /// </returns>
  593. public static IMongoQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IMongoQueryable<TOuter> outer, IMongoCollection<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector)
  594. {
  595. return GroupJoin(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
  596. }
  597. /// <summary>
  598. /// Correlates the elements of two sequences based on matching keys.
  599. /// </summary>
  600. /// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
  601. /// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
  602. /// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
  603. /// <typeparam name="TResult">The type of the result elements.</typeparam>
  604. /// <param name="outer">The first sequence to join.</param>
  605. /// <param name="inner">The sequence to join to the first sequence.</param>
  606. /// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
  607. /// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
  608. /// <param name="resultSelector">A function to create a result element from two matching elements.</param>
  609. /// <returns>
  610. /// An <see cref="T:System.Linq.IQueryable`1" /> that has elements of type <typeparamref name="TResult" /> obtained by performing an inner join on two sequences.
  611. /// </returns>
  612. public static IMongoQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IMongoQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector)
  613. {
  614. return (IMongoQueryable<TResult>)Queryable.Join(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
  615. }
  616. /// <summary>
  617. /// Correlates the elements of two sequences based on matching keys.
  618. /// </summary>
  619. /// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
  620. /// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
  621. /// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
  622. /// <typeparam name="TResult">The type of the result elements.</typeparam>
  623. /// <param name="outer">The first sequence to join.</param>
  624. /// <param name="inner">The sequence to join to the first sequence.</param>
  625. /// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
  626. /// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
  627. /// <param name="resultSelector">A function to create a result element from two matching elements.</param>
  628. /// <returns>
  629. /// An <see cref="T:System.Linq.IQueryable`1" /> that has elements of type <typeparamref name="TResult" /> obtained by performing an inner join on two sequences.
  630. /// </returns>
  631. public static IMongoQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IMongoQueryable<TOuter> outer, IMongoCollection<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector)
  632. {
  633. return Join(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
  634. }
  635. /// <summary>
  636. /// Returns the number of elements in a sequence.
  637. /// </summary>
  638. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  639. /// <param name="source">The <see cref="IMongoQueryable{TSource}" /> that contains the elements to be counted.</param>
  640. /// <param name="cancellationToken">The cancellation token.</param>
  641. /// <returns>
  642. /// The number of elements in the input sequence.
  643. /// </returns>
  644. public static Task<long> LongCountAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  645. {
  646. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long>(
  647. Expression.Call(
  648. GetMethodInfo<IQueryable<TSource>, long>(Queryable.LongCount, source),
  649. source.Expression),
  650. cancellationToken);
  651. }
  652. /// <summary>
  653. /// Returns the number of elements in the specified sequence that satisfies a condition.
  654. /// </summary>
  655. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  656. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> that contains the elements to be counted.</param>
  657. /// <param name="predicate">A function to test each element for a condition.</param>
  658. /// <param name="cancellationToken">The cancellation token.</param>
  659. /// <returns>
  660. /// The number of elements in the sequence that satisfies the condition in the predicate function.
  661. /// </returns>
  662. public static Task<long> LongCountAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  663. {
  664. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long>(
  665. Expression.Call(
  666. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, long>(Queryable.LongCount, source, predicate),
  667. source.Expression,
  668. Expression.Quote(predicate)),
  669. cancellationToken);
  670. }
  671. /// <summary>
  672. /// Returns the maximum value in a generic <see cref="IMongoQueryable{TSource}" />.
  673. /// </summary>
  674. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  675. /// <param name="source">A sequence of values to determine the maximum of.</param>
  676. /// <param name="cancellationToken">The cancellation token.</param>
  677. /// <returns>
  678. /// The maximum value in the sequence.
  679. /// </returns>
  680. public static Task<TSource> MaxAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  681. {
  682. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  683. Expression.Call(
  684. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.Max, source),
  685. source.Expression),
  686. cancellationToken);
  687. }
  688. /// <summary>
  689. /// Invokes a projection function on each element of a generic <see cref="IMongoQueryable{TSource}" /> and returns the maximum resulting value.
  690. /// </summary>
  691. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  692. /// <typeparam name="TResult">The type of the value returned by the function represented by <paramref name="selector" />.</typeparam>
  693. /// <param name="source">A sequence of values to determine the maximum of.</param>
  694. /// <param name="selector">A projection function to apply to each element.</param>
  695. /// <param name="cancellationToken">The cancellation token.</param>
  696. /// <returns>
  697. /// The maximum value in the sequence.
  698. /// </returns>
  699. public static Task<TResult> MaxAsync<TSource, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken cancellationToken = default(CancellationToken))
  700. {
  701. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TResult>(
  702. Expression.Call(
  703. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, TResult>>, TResult>(Queryable.Max, source, selector),
  704. source.Expression,
  705. Expression.Quote(selector)),
  706. cancellationToken);
  707. }
  708. /// <summary>
  709. /// Returns the minimum value in a generic <see cref="IMongoQueryable{TSource}" />.
  710. /// </summary>
  711. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  712. /// <param name="source">A sequence of values to determine the minimum of.</param>
  713. /// <param name="cancellationToken">The cancellation token.</param>
  714. /// <returns>
  715. /// The minimum value in the sequence.
  716. /// </returns>
  717. public static Task<TSource> MinAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  718. {
  719. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  720. Expression.Call(
  721. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.Min, source),
  722. source.Expression),
  723. cancellationToken);
  724. }
  725. /// <summary>
  726. /// Invokes a projection function on each element of a generic <see cref="IMongoQueryable{TSource}" /> and returns the minimum resulting value.
  727. /// </summary>
  728. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  729. /// <typeparam name="TResult">The type of the value returned by the function represented by <paramref name="selector" />.</typeparam>
  730. /// <param name="source">A sequence of values to determine the minimum of.</param>
  731. /// <param name="selector">A projection function to apply to each element.</param>
  732. /// <param name="cancellationToken">The cancellation token.</param>
  733. /// <returns>
  734. /// The minimum value in the sequence.
  735. /// </returns>
  736. public static Task<TResult> MinAsync<TSource, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken cancellationToken = default(CancellationToken))
  737. {
  738. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TResult>(
  739. Expression.Call(
  740. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, TResult>>, TResult>(Queryable.Min, source, selector),
  741. source.Expression,
  742. Expression.Quote(selector)),
  743. cancellationToken);
  744. }
  745. /// <summary>
  746. /// Filters the elements of an <see cref="IMongoQueryable" /> based on a specified type.
  747. /// </summary>
  748. /// <typeparam name="TResult">The type to filter the elements of the sequence on.</typeparam>
  749. /// <param name="source">An <see cref="IMongoQueryable" /> whose elements to filter.</param>
  750. /// <returns>
  751. /// A collection that contains the elements from <paramref name="source" /> that have type <typeparamref name="TResult" />.
  752. /// </returns>
  753. public static IMongoQueryable<TResult> OfType<TResult>(this IMongoQueryable source)
  754. {
  755. return (IMongoQueryable<TResult>)Queryable.OfType<TResult>(source);
  756. }
  757. /// <summary>
  758. /// Sorts the elements of a sequence in ascending order according to a key.
  759. /// </summary>
  760. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  761. /// <typeparam name="TKey">The type of the key returned by the function that is represented by keySelector.</typeparam>
  762. /// <param name="source">A sequence of values to order.</param>
  763. /// <param name="keySelector">A function to extract a key from an element.</param>
  764. /// <returns>
  765. /// An <see cref="IOrderedMongoQueryable{TSource}"/> whose elements are sorted according to a key.
  766. /// </returns>
  767. public static IOrderedMongoQueryable<TSource> OrderBy<TSource, TKey>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  768. {
  769. return (IOrderedMongoQueryable<TSource>)Queryable.OrderBy(source, keySelector);
  770. }
  771. /// <summary>
  772. /// Sorts the elements of a sequence in descending order according to a key.
  773. /// </summary>
  774. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  775. /// <typeparam name="TKey">The type of the key returned by the function that is represented by keySelector.</typeparam>
  776. /// <param name="source">A sequence of values to order.</param>
  777. /// <param name="keySelector">A function to extract a key from an element.</param>
  778. /// <returns>
  779. /// An <see cref="IOrderedMongoQueryable{TSource}"/> whose elements are sorted in descending order according to a key.
  780. /// </returns>
  781. public static IOrderedMongoQueryable<TSource> OrderByDescending<TSource, TKey>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  782. {
  783. return (IOrderedMongoQueryable<TSource>)Queryable.OrderByDescending(source, keySelector);
  784. }
  785. /// <summary>
  786. /// Returns a sample of the elements in the <paramref name="source"/>.
  787. /// </summary>
  788. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  789. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return a sample of.</param>
  790. /// <param name="count">The number of elements in the sample.</param>
  791. /// <returns>
  792. /// A sample of the elements in the <paramref name="source"/>.
  793. /// </returns>
  794. public static IMongoQueryable<TSource> Sample<TSource>(this IMongoQueryable<TSource> source, long count)
  795. {
  796. return (IMongoQueryable<TSource>)source.Provider.CreateQuery<TSource>(
  797. Expression.Call(
  798. null,
  799. GetMethodInfo(Sample, source, count),
  800. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  801. Expression.Constant(count)));
  802. }
  803. /// <summary>
  804. /// Projects each element of a sequence into a new form by incorporating the
  805. /// element's index.
  806. /// </summary>
  807. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  808. /// <typeparam name="TResult"> The type of the value returned by the function represented by selector.</typeparam>
  809. /// <param name="source">A sequence of values to project.</param>
  810. /// <param name="selector">A projection function to apply to each element.</param>
  811. /// <returns>
  812. /// An <see cref="IMongoQueryable{TResult}"/> whose elements are the result of invoking a
  813. /// projection function on each element of source.
  814. /// </returns>
  815. public static IMongoQueryable<TResult> Select<TSource, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
  816. {
  817. return (IMongoQueryable<TResult>)Queryable.Select(source, selector);
  818. }
  819. /// <summary>
  820. /// Projects each element of a sequence to an <see cref="IEnumerable{TResult}" /> and combines the resulting sequences into one sequence.
  821. /// </summary>
  822. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  823. /// <typeparam name="TResult">The type of the elements of the sequence returned by the function represented by <paramref name="selector" />.</typeparam>
  824. /// <param name="source">A sequence of values to project.</param>
  825. /// <param name="selector">A projection function to apply to each element.</param>
  826. /// <returns>
  827. /// An <see cref="IMongoQueryable{TResult}" /> whose elements are the result of invoking a one-to-many projection function on each element of the input sequence.
  828. /// </returns>
  829. public static IMongoQueryable<TResult> SelectMany<TSource, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TResult>>> selector)
  830. {
  831. return (IMongoQueryable<TResult>)Queryable.SelectMany(source, selector);
  832. }
  833. /// <summary>
  834. /// Projects each element of a sequence to an <see cref="IEnumerable{TCollection}" /> and
  835. /// invokes a result selector function on each element therein. The resulting values from
  836. /// each intermediate sequence are combined into a single, one-dimensional sequence and returned.
  837. /// </summary>
  838. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  839. /// <typeparam name="TCollection">The type of the intermediate elements collected by the function represented by <paramref name="collectionSelector" />.</typeparam>
  840. /// <typeparam name="TResult">The type of the elements of the resulting sequence.</typeparam>
  841. /// <param name="source">A sequence of values to project.</param>
  842. /// <param name="collectionSelector">A projection function to apply to each element of the input sequence.</param>
  843. /// <param name="resultSelector">A projection function to apply to each element of each intermediate sequence.</param>
  844. /// <returns>
  845. /// An <see cref="IMongoQueryable{TResult}" /> whose elements are the result of invoking the one-to-many projection function <paramref name="collectionSelector" /> on each element of <paramref name="source" /> and then mapping each of those sequence elements and their corresponding <paramref name="source" /> element to a result element.
  846. /// </returns>
  847. public static IMongoQueryable<TResult> SelectMany<TSource, TCollection, TResult>(this IMongoQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TCollection>>> collectionSelector, Expression<Func<TSource, TCollection, TResult>> resultSelector)
  848. {
  849. return (IMongoQueryable<TResult>)Queryable.SelectMany(source, collectionSelector, resultSelector);
  850. }
  851. /// <summary>
  852. /// Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
  853. /// </summary>
  854. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  855. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return the single element of.</param>
  856. /// <param name="cancellationToken">The cancellation token.</param>
  857. /// <returns>
  858. /// The single element of the input sequence.
  859. /// </returns>
  860. public static Task<TSource> SingleAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  861. {
  862. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  863. Expression.Call(
  864. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.Single, source),
  865. source.Expression),
  866. cancellationToken);
  867. }
  868. /// <summary>
  869. /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.
  870. /// </summary>
  871. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  872. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return a single element from.</param>
  873. /// <param name="predicate">A function to test an element for a condition.</param>
  874. /// <param name="cancellationToken">The cancellation token.</param>
  875. /// <returns>
  876. /// The single element of the input sequence that satisfies the condition in <paramref name="predicate" />.
  877. /// </returns>
  878. public static Task<TSource> SingleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  879. {
  880. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  881. Expression.Call(
  882. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, TSource>(Queryable.Single, source, predicate),
  883. source.Expression,
  884. Expression.Quote(predicate)),
  885. cancellationToken);
  886. }
  887. /// <summary>
  888. /// Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
  889. /// </summary>
  890. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  891. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return the single element of.</param>
  892. /// <param name="cancellationToken">The cancellation token.</param>
  893. /// <returns>
  894. /// The single element of the input sequence, or default(<typeparamref name="TSource" />) if the sequence contains no elements.
  895. /// </returns>
  896. public static Task<TSource> SingleOrDefaultAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default(CancellationToken))
  897. {
  898. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  899. Expression.Call(
  900. GetMethodInfo<IQueryable<TSource>, TSource>(Queryable.SingleOrDefault, source),
  901. source.Expression),
  902. cancellationToken);
  903. }
  904. /// <summary>
  905. /// Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.
  906. /// </summary>
  907. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  908. /// <param name="source">An <see cref="IMongoQueryable{TSource}" /> to return a single element from.</param>
  909. /// <param name="predicate">A function to test an element for a condition.</param>
  910. /// <param name="cancellationToken">The cancellation token.</param>
  911. /// <returns>
  912. /// The single element of the input sequence that satisfies the condition in <paramref name="predicate" />, or default(<typeparamref name="TSource" />) if no such element is found.
  913. /// </returns>
  914. public static Task<TSource> SingleOrDefaultAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
  915. {
  916. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<TSource>(
  917. Expression.Call(
  918. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, bool>>, TSource>(Queryable.SingleOrDefault, source, predicate),
  919. source.Expression,
  920. Expression.Quote(predicate)),
  921. cancellationToken);
  922. }
  923. /// <summary>
  924. /// Bypasses a specified number of elements in a sequence and then returns the
  925. /// remaining elements.
  926. /// </summary>
  927. /// <typeparam name="TSource">The type of the elements of source</typeparam>
  928. /// <param name="source">An <see cref="IMongoQueryable{TSource}"/> to return elements from.</param>
  929. /// <param name="count">The number of elements to skip before returning the remaining elements.</param>
  930. /// <returns>
  931. /// An <see cref="IMongoQueryable{TSource}"/> that contains elements that occur after the
  932. /// specified index in the input sequence.
  933. /// </returns>
  934. public static IMongoQueryable<TSource> Skip<TSource>(this IMongoQueryable<TSource> source, int count)
  935. {
  936. return (IMongoQueryable<TSource>)Queryable.Skip(source, count);
  937. }
  938. /// <summary>
  939. /// Computes the population standard deviation of a sequence of values.
  940. /// </summary>
  941. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  942. /// <returns>
  943. /// The population standard deviation of the sequence of values.
  944. /// </returns>
  945. public static double StandardDeviationPopulation(this IMongoQueryable<int> source)
  946. {
  947. return source.Provider.Execute<double>(
  948. Expression.Call(
  949. GetMethodInfo(StandardDeviationPopulation, source),
  950. Expression.Convert(source.Expression, typeof(IMongoQueryable<int>))));
  951. }
  952. /// <summary>
  953. /// Computes the population standard deviation of a sequence of values.
  954. /// </summary>
  955. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  956. /// <returns>
  957. /// The population standard deviation of the sequence of values.
  958. /// </returns>
  959. public static double? StandardDeviationPopulation(this IMongoQueryable<int?> source)
  960. {
  961. return source.Provider.Execute<double?>(
  962. Expression.Call(
  963. GetMethodInfo(StandardDeviationPopulation, source),
  964. Expression.Convert(source.Expression, typeof(IMongoQueryable<int?>))));
  965. }
  966. /// <summary>
  967. /// Computes the population standard deviation of a sequence of values.
  968. /// </summary>
  969. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  970. /// <returns>
  971. /// The population standard deviation of the sequence of values.
  972. /// </returns>
  973. public static double StandardDeviationPopulation(this IMongoQueryable<long> source)
  974. {
  975. return source.Provider.Execute<double>(
  976. Expression.Call(
  977. GetMethodInfo(StandardDeviationPopulation, source),
  978. Expression.Convert(source.Expression, typeof(IMongoQueryable<long>))));
  979. }
  980. /// <summary>
  981. /// Computes the population standard deviation of a sequence of values.
  982. /// </summary>
  983. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  984. /// <returns>
  985. /// The population standard deviation of the sequence of values.
  986. /// </returns>
  987. public static double? StandardDeviationPopulation(this IMongoQueryable<long?> source)
  988. {
  989. return source.Provider.Execute<double?>(
  990. Expression.Call(
  991. GetMethodInfo(StandardDeviationPopulation, source),
  992. Expression.Convert(source.Expression, typeof(IMongoQueryable<long?>))));
  993. }
  994. /// <summary>
  995. /// Computes the population standard deviation of a sequence of values.
  996. /// </summary>
  997. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  998. /// <returns>
  999. /// The population standard deviation of the sequence of values.
  1000. /// </returns>
  1001. public static float StandardDeviationPopulation(this IMongoQueryable<float> source)
  1002. {
  1003. return source.Provider.Execute<float>(
  1004. Expression.Call(
  1005. GetMethodInfo(StandardDeviationPopulation, source),
  1006. Expression.Convert(source.Expression, typeof(IMongoQueryable<float>))));
  1007. }
  1008. /// <summary>
  1009. /// Computes the population standard deviation of a sequence of values.
  1010. /// </summary>
  1011. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1012. /// <returns>
  1013. /// The population standard deviation of the sequence of values.
  1014. /// </returns>
  1015. public static float? StandardDeviationPopulation(this IMongoQueryable<float?> source)
  1016. {
  1017. return source.Provider.Execute<float?>(
  1018. Expression.Call(
  1019. GetMethodInfo(StandardDeviationPopulation, source),
  1020. Expression.Convert(source.Expression, typeof(IMongoQueryable<float?>))));
  1021. }
  1022. /// <summary>
  1023. /// Computes the population standard deviation of a sequence of values.
  1024. /// </summary>
  1025. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1026. /// <returns>
  1027. /// The population standard deviation of the sequence of values.
  1028. /// </returns>
  1029. public static double StandardDeviationPopulation(this IMongoQueryable<double> source)
  1030. {
  1031. return source.Provider.Execute<double>(
  1032. Expression.Call(
  1033. GetMethodInfo(StandardDeviationPopulation, source),
  1034. Expression.Convert(source.Expression, typeof(IMongoQueryable<double>))));
  1035. }
  1036. /// <summary>
  1037. /// Computes the population standard deviation of a sequence of values.
  1038. /// </summary>
  1039. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1040. /// <returns>
  1041. /// The population standard deviation of the sequence of values.
  1042. /// </returns>
  1043. public static double? StandardDeviationPopulation(this IMongoQueryable<double?> source)
  1044. {
  1045. return source.Provider.Execute<double?>(
  1046. Expression.Call(
  1047. GetMethodInfo(StandardDeviationPopulation, source),
  1048. Expression.Convert(source.Expression, typeof(IMongoQueryable<double?>))));
  1049. }
  1050. /// <summary>
  1051. /// Computes the population standard deviation of a sequence of values.
  1052. /// </summary>
  1053. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1054. /// <returns>
  1055. /// The population standard deviation of the sequence of values.
  1056. /// </returns>
  1057. public static decimal StandardDeviationPopulation(this IMongoQueryable<decimal> source)
  1058. {
  1059. return source.Provider.Execute<decimal>(
  1060. Expression.Call(
  1061. GetMethodInfo(StandardDeviationPopulation, source),
  1062. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal>))));
  1063. }
  1064. /// <summary>
  1065. /// Computes the population standard deviation of a sequence of values.
  1066. /// </summary>
  1067. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1068. /// <returns>
  1069. /// The population standard deviation of the sequence of values.
  1070. /// </returns>
  1071. public static decimal? StandardDeviationPopulation(this IMongoQueryable<decimal?> source)
  1072. {
  1073. return source.Provider.Execute<decimal?>(
  1074. Expression.Call(
  1075. GetMethodInfo(StandardDeviationPopulation, source),
  1076. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal?>))));
  1077. }
  1078. /// <summary>
  1079. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1080. /// </summary>
  1081. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1082. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1083. /// <param name="selector">A transform function to apply to each element.</param>
  1084. /// <returns>
  1085. /// The population standard deviation of the sequence of values.
  1086. /// </returns>
  1087. public static double StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector)
  1088. {
  1089. return source.Provider.Execute<double>(
  1090. Expression.Call(
  1091. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1092. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1093. Expression.Quote(selector)));
  1094. }
  1095. /// <summary>
  1096. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1097. /// </summary>
  1098. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1099. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1100. /// <param name="selector">A transform function to apply to each element.</param>
  1101. /// <returns>
  1102. /// The population standard deviation of the sequence of values.
  1103. /// </returns>
  1104. public static double? StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector)
  1105. {
  1106. return source.Provider.Execute<double?>(
  1107. Expression.Call(
  1108. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1109. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1110. Expression.Quote(selector)));
  1111. }
  1112. /// <summary>
  1113. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1114. /// </summary>
  1115. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1116. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1117. /// <param name="selector">A transform function to apply to each element.</param>
  1118. /// <returns>
  1119. /// The population standard deviation of the sequence of values.
  1120. /// </returns>
  1121. public static double StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector)
  1122. {
  1123. return source.Provider.Execute<double>(
  1124. Expression.Call(
  1125. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1126. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1127. Expression.Quote(selector)));
  1128. }
  1129. /// <summary>
  1130. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1131. /// </summary>
  1132. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1133. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1134. /// <param name="selector">A transform function to apply to each element.</param>
  1135. /// <returns>
  1136. /// The population standard deviation of the sequence of values.
  1137. /// </returns>
  1138. public static double? StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector)
  1139. {
  1140. return source.Provider.Execute<double?>(
  1141. Expression.Call(
  1142. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1143. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1144. Expression.Quote(selector)));
  1145. }
  1146. /// <summary>
  1147. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1148. /// </summary>
  1149. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1150. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1151. /// <param name="selector">A transform function to apply to each element.</param>
  1152. /// <returns>
  1153. /// The population standard deviation of the sequence of values.
  1154. /// </returns>
  1155. public static float StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector)
  1156. {
  1157. return source.Provider.Execute<float>(
  1158. Expression.Call(
  1159. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1160. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1161. Expression.Quote(selector)));
  1162. }
  1163. /// <summary>
  1164. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1165. /// </summary>
  1166. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1167. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1168. /// <param name="selector">A transform function to apply to each element.</param>
  1169. /// <returns>
  1170. /// The population standard deviation of the sequence of values.
  1171. /// </returns>
  1172. public static float? StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector)
  1173. {
  1174. return source.Provider.Execute<float?>(
  1175. Expression.Call(
  1176. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1177. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1178. Expression.Quote(selector)));
  1179. }
  1180. /// <summary>
  1181. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1182. /// </summary>
  1183. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1184. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1185. /// <param name="selector">A transform function to apply to each element.</param>
  1186. /// <returns>
  1187. /// The population standard deviation of the sequence of values.
  1188. /// </returns>
  1189. public static double StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector)
  1190. {
  1191. return source.Provider.Execute<double>(
  1192. Expression.Call(
  1193. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1194. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1195. Expression.Quote(selector)));
  1196. }
  1197. /// <summary>
  1198. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1199. /// </summary>
  1200. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1201. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1202. /// <param name="selector">A transform function to apply to each element.</param>
  1203. /// <returns>
  1204. /// The population standard deviation of the sequence of values.
  1205. /// </returns>
  1206. public static double? StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector)
  1207. {
  1208. return source.Provider.Execute<double?>(
  1209. Expression.Call(
  1210. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1211. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1212. Expression.Quote(selector)));
  1213. }
  1214. /// <summary>
  1215. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1216. /// </summary>
  1217. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1218. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1219. /// <param name="selector">A transform function to apply to each element.</param>
  1220. /// <returns>
  1221. /// The population standard deviation of the sequence of values.
  1222. /// </returns>
  1223. public static decimal StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector)
  1224. {
  1225. return source.Provider.Execute<decimal>(
  1226. Expression.Call(
  1227. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1228. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1229. Expression.Quote(selector)));
  1230. }
  1231. /// <summary>
  1232. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1233. /// </summary>
  1234. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1235. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1236. /// <param name="selector">A transform function to apply to each element.</param>
  1237. /// <returns>
  1238. /// The population standard deviation of the sequence of values.
  1239. /// </returns>
  1240. public static decimal? StandardDeviationPopulation<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector)
  1241. {
  1242. return source.Provider.Execute<decimal?>(
  1243. Expression.Call(
  1244. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1245. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1246. Expression.Quote(selector)));
  1247. }
  1248. /// <summary>
  1249. /// Computes the population standard deviation of a sequence of values.
  1250. /// </summary>
  1251. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1252. /// <param name="cancellationToken">The cancellation token.</param>
  1253. /// <returns>
  1254. /// The population standard deviation of the sequence of values.
  1255. /// </returns>
  1256. public static Task<double> StandardDeviationPopulationAsync(this IMongoQueryable<int> source, CancellationToken cancellationToken = default(CancellationToken))
  1257. {
  1258. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1259. Expression.Call(
  1260. GetMethodInfo(StandardDeviationPopulation, source),
  1261. Expression.Convert(source.Expression, typeof(IMongoQueryable<int>))),
  1262. cancellationToken);
  1263. }
  1264. /// <summary>
  1265. /// Computes the population standard deviation of a sequence of values.
  1266. /// </summary>
  1267. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1268. /// <param name="cancellationToken">The cancellation token.</param>
  1269. /// <returns>
  1270. /// The population standard deviation of the sequence of values.
  1271. /// </returns>
  1272. public static Task<double?> StandardDeviationPopulationAsync(this IMongoQueryable<int?> source, CancellationToken cancellationToken = default(CancellationToken))
  1273. {
  1274. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1275. Expression.Call(
  1276. GetMethodInfo(StandardDeviationPopulation, source),
  1277. Expression.Convert(source.Expression, typeof(IMongoQueryable<int?>))),
  1278. cancellationToken);
  1279. }
  1280. /// <summary>
  1281. /// Computes the population standard deviation of a sequence of values.
  1282. /// </summary>
  1283. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1284. /// <param name="cancellationToken">The cancellation token.</param>
  1285. /// <returns>
  1286. /// The population standard deviation of the sequence of values.
  1287. /// </returns>
  1288. public static Task<double> StandardDeviationPopulationAsync(this IMongoQueryable<long> source, CancellationToken cancellationToken = default(CancellationToken))
  1289. {
  1290. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1291. Expression.Call(
  1292. GetMethodInfo(StandardDeviationPopulation, source),
  1293. Expression.Convert(source.Expression, typeof(IMongoQueryable<long>))),
  1294. cancellationToken);
  1295. }
  1296. /// <summary>
  1297. /// Computes the population standard deviation of a sequence of values.
  1298. /// </summary>
  1299. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1300. /// <param name="cancellationToken">The cancellation token.</param>
  1301. /// <returns>
  1302. /// The population standard deviation of the sequence of values.
  1303. /// </returns>
  1304. public static Task<double?> StandardDeviationPopulationAsync(this IMongoQueryable<long?> source, CancellationToken cancellationToken = default(CancellationToken))
  1305. {
  1306. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1307. Expression.Call(
  1308. GetMethodInfo(StandardDeviationPopulation, source),
  1309. Expression.Convert(source.Expression, typeof(IMongoQueryable<long?>))),
  1310. cancellationToken);
  1311. }
  1312. /// <summary>
  1313. /// Computes the population standard deviation of a sequence of values.
  1314. /// </summary>
  1315. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1316. /// <param name="cancellationToken">The cancellation token.</param>
  1317. /// <returns>
  1318. /// The population standard deviation of the sequence of values.
  1319. /// </returns>
  1320. public static Task<float> StandardDeviationPopulationAsync(this IMongoQueryable<float> source, CancellationToken cancellationToken = default(CancellationToken))
  1321. {
  1322. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  1323. Expression.Call(
  1324. GetMethodInfo(StandardDeviationPopulation, source),
  1325. Expression.Convert(source.Expression, typeof(IMongoQueryable<float>))),
  1326. cancellationToken);
  1327. }
  1328. /// <summary>
  1329. /// Computes the population standard deviation of a sequence of values.
  1330. /// </summary>
  1331. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1332. /// <param name="cancellationToken">The cancellation token.</param>
  1333. /// <returns>
  1334. /// The population standard deviation of the sequence of values.
  1335. /// </returns>
  1336. public static Task<float?> StandardDeviationPopulationAsync(this IMongoQueryable<float?> source, CancellationToken cancellationToken = default(CancellationToken))
  1337. {
  1338. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  1339. Expression.Call(
  1340. GetMethodInfo(StandardDeviationPopulation, source),
  1341. Expression.Convert(source.Expression, typeof(IMongoQueryable<float?>))),
  1342. cancellationToken);
  1343. }
  1344. /// <summary>
  1345. /// Computes the population standard deviation of a sequence of values.
  1346. /// </summary>
  1347. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1348. /// <param name="cancellationToken">The cancellation token.</param>
  1349. /// <returns>
  1350. /// The population standard deviation of the sequence of values.
  1351. /// </returns>
  1352. public static Task<double> StandardDeviationPopulationAsync(this IMongoQueryable<double> source, CancellationToken cancellationToken = default(CancellationToken))
  1353. {
  1354. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1355. Expression.Call(
  1356. GetMethodInfo(StandardDeviationPopulation, source),
  1357. Expression.Convert(source.Expression, typeof(IMongoQueryable<double>))),
  1358. cancellationToken);
  1359. }
  1360. /// <summary>
  1361. /// Computes the population standard deviation of a sequence of values.
  1362. /// </summary>
  1363. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1364. /// <param name="cancellationToken">The cancellation token.</param>
  1365. /// <returns>
  1366. /// The population standard deviation of the sequence of values.
  1367. /// </returns>
  1368. public static Task<double?> StandardDeviationPopulationAsync(this IMongoQueryable<double?> source, CancellationToken cancellationToken = default(CancellationToken))
  1369. {
  1370. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1371. Expression.Call(
  1372. GetMethodInfo(StandardDeviationPopulation, source),
  1373. Expression.Convert(source.Expression, typeof(IMongoQueryable<double?>))),
  1374. cancellationToken);
  1375. }
  1376. /// <summary>
  1377. /// Computes the population standard deviation of a sequence of values.
  1378. /// </summary>
  1379. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1380. /// <param name="cancellationToken">The cancellation token.</param>
  1381. /// <returns>
  1382. /// The population standard deviation of the sequence of values.
  1383. /// </returns>
  1384. public static Task<decimal> StandardDeviationPopulationAsync(this IMongoQueryable<decimal> source, CancellationToken cancellationToken = default(CancellationToken))
  1385. {
  1386. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  1387. Expression.Call(
  1388. GetMethodInfo(StandardDeviationPopulation, source),
  1389. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal>))),
  1390. cancellationToken);
  1391. }
  1392. /// <summary>
  1393. /// Computes the population standard deviation of a sequence of values.
  1394. /// </summary>
  1395. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1396. /// <param name="cancellationToken">The cancellation token.</param>
  1397. /// <returns>
  1398. /// The population standard deviation of the sequence of values.
  1399. /// </returns>
  1400. public static Task<decimal?> StandardDeviationPopulationAsync(this IMongoQueryable<decimal?> source, CancellationToken cancellationToken = default(CancellationToken))
  1401. {
  1402. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  1403. Expression.Call(
  1404. GetMethodInfo(StandardDeviationPopulation, source),
  1405. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal?>))),
  1406. cancellationToken);
  1407. }
  1408. /// <summary>
  1409. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1410. /// </summary>
  1411. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1412. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1413. /// <param name="selector">A transform function to apply to each element.</param>
  1414. /// <param name="cancellationToken">The cancellation token.</param>
  1415. /// <returns>
  1416. /// The population standard deviation of the sequence of values.
  1417. /// </returns>
  1418. public static Task<double> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1419. {
  1420. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1421. Expression.Call(
  1422. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1423. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1424. Expression.Quote(selector)),
  1425. cancellationToken);
  1426. }
  1427. /// <summary>
  1428. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1429. /// </summary>
  1430. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1431. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1432. /// <param name="selector">A transform function to apply to each element.</param>
  1433. /// <param name="cancellationToken">The cancellation token.</param>
  1434. /// <returns>
  1435. /// The population standard deviation of the sequence of values.
  1436. /// </returns>
  1437. public static Task<double?> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1438. {
  1439. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1440. Expression.Call(
  1441. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1442. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1443. Expression.Quote(selector)),
  1444. cancellationToken);
  1445. }
  1446. /// <summary>
  1447. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1448. /// </summary>
  1449. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1450. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1451. /// <param name="selector">A transform function to apply to each element.</param>
  1452. /// <param name="cancellationToken">The cancellation token.</param>
  1453. /// <returns>
  1454. /// The population standard deviation of the sequence of values.
  1455. /// </returns>
  1456. public static Task<double> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1457. {
  1458. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1459. Expression.Call(
  1460. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1461. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1462. Expression.Quote(selector)),
  1463. cancellationToken);
  1464. }
  1465. /// <summary>
  1466. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1467. /// </summary>
  1468. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1469. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1470. /// <param name="selector">A transform function to apply to each element.</param>
  1471. /// <param name="cancellationToken">The cancellation token.</param>
  1472. /// <returns>
  1473. /// The population standard deviation of the sequence of values.
  1474. /// </returns>
  1475. public static Task<double?> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1476. {
  1477. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1478. Expression.Call(
  1479. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1480. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1481. Expression.Quote(selector)),
  1482. cancellationToken);
  1483. }
  1484. /// <summary>
  1485. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1486. /// </summary>
  1487. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1488. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1489. /// <param name="selector">A transform function to apply to each element.</param>
  1490. /// <param name="cancellationToken">The cancellation token.</param>
  1491. /// <returns>
  1492. /// The population standard deviation of the sequence of values.
  1493. /// </returns>
  1494. public static Task<float> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1495. {
  1496. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  1497. Expression.Call(
  1498. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1499. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1500. Expression.Quote(selector)),
  1501. cancellationToken);
  1502. }
  1503. /// <summary>
  1504. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1505. /// </summary>
  1506. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1507. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1508. /// <param name="selector">A transform function to apply to each element.</param>
  1509. /// <param name="cancellationToken">The cancellation token.</param>
  1510. /// <returns>
  1511. /// The population standard deviation of the sequence of values.
  1512. /// </returns>
  1513. public static Task<float?> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1514. {
  1515. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  1516. Expression.Call(
  1517. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1518. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1519. Expression.Quote(selector)),
  1520. cancellationToken);
  1521. }
  1522. /// <summary>
  1523. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1524. /// </summary>
  1525. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1526. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1527. /// <param name="selector">A transform function to apply to each element.</param>
  1528. /// <param name="cancellationToken">The cancellation token.</param>
  1529. /// <returns>
  1530. /// The population standard deviation of the sequence of values.
  1531. /// </returns>
  1532. public static Task<double> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1533. {
  1534. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1535. Expression.Call(
  1536. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1537. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1538. Expression.Quote(selector)),
  1539. cancellationToken);
  1540. }
  1541. /// <summary>
  1542. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1543. /// </summary>
  1544. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1545. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1546. /// <param name="selector">A transform function to apply to each element.</param>
  1547. /// <param name="cancellationToken">The cancellation token.</param>
  1548. /// <returns>
  1549. /// The population standard deviation of the sequence of values.
  1550. /// </returns>
  1551. public static Task<double?> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1552. {
  1553. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1554. Expression.Call(
  1555. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1556. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1557. Expression.Quote(selector)),
  1558. cancellationToken);
  1559. }
  1560. /// <summary>
  1561. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1562. /// </summary>
  1563. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1564. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1565. /// <param name="selector">A transform function to apply to each element.</param>
  1566. /// <param name="cancellationToken">The cancellation token.</param>
  1567. /// <returns>
  1568. /// The population standard deviation of the sequence of values.
  1569. /// </returns>
  1570. public static Task<decimal> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1571. {
  1572. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  1573. Expression.Call(
  1574. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1575. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1576. Expression.Quote(selector)),
  1577. cancellationToken);
  1578. }
  1579. /// <summary>
  1580. /// Computes the population standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1581. /// </summary>
  1582. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1583. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1584. /// <param name="selector">A transform function to apply to each element.</param>
  1585. /// <param name="cancellationToken">The cancellation token.</param>
  1586. /// <returns>
  1587. /// The population standard deviation of the sequence of values.
  1588. /// </returns>
  1589. public static Task<decimal?> StandardDeviationPopulationAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  1590. {
  1591. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  1592. Expression.Call(
  1593. GetMethodInfo(StandardDeviationPopulation, source, selector),
  1594. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1595. Expression.Quote(selector)),
  1596. cancellationToken);
  1597. }
  1598. /// <summary>
  1599. /// Computes the sample standard deviation of a sequence of values.
  1600. /// </summary>
  1601. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1602. /// <returns>
  1603. /// The population standard deviation of the sequence of values.
  1604. /// </returns>
  1605. public static double StandardDeviationSample(this IMongoQueryable<int> source)
  1606. {
  1607. return source.Provider.Execute<double>(
  1608. Expression.Call(
  1609. GetMethodInfo(StandardDeviationSample, source),
  1610. Expression.Convert(source.Expression, typeof(IMongoQueryable<int>))));
  1611. }
  1612. /// <summary>
  1613. /// Computes the sample standard deviation of a sequence of values.
  1614. /// </summary>
  1615. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1616. /// <returns>
  1617. /// The population standard deviation of the sequence of values.
  1618. /// </returns>
  1619. public static double? StandardDeviationSample(this IMongoQueryable<int?> source)
  1620. {
  1621. return source.Provider.Execute<double?>(
  1622. Expression.Call(
  1623. GetMethodInfo(StandardDeviationSample, source),
  1624. Expression.Convert(source.Expression, typeof(IMongoQueryable<int?>))));
  1625. }
  1626. /// <summary>
  1627. /// Computes the sample standard deviation of a sequence of values.
  1628. /// </summary>
  1629. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1630. /// <returns>
  1631. /// The population standard deviation of the sequence of values.
  1632. /// </returns>
  1633. public static double StandardDeviationSample(this IMongoQueryable<long> source)
  1634. {
  1635. return source.Provider.Execute<double>(
  1636. Expression.Call(
  1637. GetMethodInfo(StandardDeviationSample, source),
  1638. Expression.Convert(source.Expression, typeof(IMongoQueryable<long>))));
  1639. }
  1640. /// <summary>
  1641. /// Computes the sample standard deviation of a sequence of values.
  1642. /// </summary>
  1643. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1644. /// <returns>
  1645. /// The population standard deviation of the sequence of values.
  1646. /// </returns>
  1647. public static double? StandardDeviationSample(this IMongoQueryable<long?> source)
  1648. {
  1649. return source.Provider.Execute<double?>(
  1650. Expression.Call(
  1651. GetMethodInfo(StandardDeviationSample, source),
  1652. Expression.Convert(source.Expression, typeof(IMongoQueryable<long?>))));
  1653. }
  1654. /// <summary>
  1655. /// Computes the sample standard deviation of a sequence of values.
  1656. /// </summary>
  1657. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1658. /// <returns>
  1659. /// The population standard deviation of the sequence of values.
  1660. /// </returns>
  1661. public static float StandardDeviationSample(this IMongoQueryable<float> source)
  1662. {
  1663. return source.Provider.Execute<float>(
  1664. Expression.Call(
  1665. GetMethodInfo(StandardDeviationSample, source),
  1666. Expression.Convert(source.Expression, typeof(IMongoQueryable<float>))));
  1667. }
  1668. /// <summary>
  1669. /// Computes the sample standard deviation of a sequence of values.
  1670. /// </summary>
  1671. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1672. /// <returns>
  1673. /// The population standard deviation of the sequence of values.
  1674. /// </returns>
  1675. public static float? StandardDeviationSample(this IMongoQueryable<float?> source)
  1676. {
  1677. return source.Provider.Execute<float?>(
  1678. Expression.Call(
  1679. GetMethodInfo(StandardDeviationSample, source),
  1680. Expression.Convert(source.Expression, typeof(IMongoQueryable<float?>))));
  1681. }
  1682. /// <summary>
  1683. /// Computes the sample standard deviation of a sequence of values.
  1684. /// </summary>
  1685. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1686. /// <returns>
  1687. /// The population standard deviation of the sequence of values.
  1688. /// </returns>
  1689. public static double StandardDeviationSample(this IMongoQueryable<double> source)
  1690. {
  1691. return source.Provider.Execute<double>(
  1692. Expression.Call(
  1693. GetMethodInfo(StandardDeviationSample, source),
  1694. Expression.Convert(source.Expression, typeof(IMongoQueryable<double>))));
  1695. }
  1696. /// <summary>
  1697. /// Computes the sample standard deviation of a sequence of values.
  1698. /// </summary>
  1699. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1700. /// <returns>
  1701. /// The population standard deviation of the sequence of values.
  1702. /// </returns>
  1703. public static double? StandardDeviationSample(this IMongoQueryable<double?> source)
  1704. {
  1705. return source.Provider.Execute<double?>(
  1706. Expression.Call(
  1707. GetMethodInfo(StandardDeviationSample, source),
  1708. Expression.Convert(source.Expression, typeof(IMongoQueryable<double?>))));
  1709. }
  1710. /// <summary>
  1711. /// Computes the sample standard deviation of a sequence of values.
  1712. /// </summary>
  1713. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1714. /// <returns>
  1715. /// The population standard deviation of the sequence of values.
  1716. /// </returns>
  1717. public static decimal StandardDeviationSample(this IMongoQueryable<decimal> source)
  1718. {
  1719. return source.Provider.Execute<decimal>(
  1720. Expression.Call(
  1721. GetMethodInfo(StandardDeviationSample, source),
  1722. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal>))));
  1723. }
  1724. /// <summary>
  1725. /// Computes the sample standard deviation of a sequence of values.
  1726. /// </summary>
  1727. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1728. /// <returns>
  1729. /// The population standard deviation of the sequence of values.
  1730. /// </returns>
  1731. public static decimal? StandardDeviationSample(this IMongoQueryable<decimal?> source)
  1732. {
  1733. return source.Provider.Execute<decimal?>(
  1734. Expression.Call(
  1735. GetMethodInfo(StandardDeviationSample, source),
  1736. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal?>))));
  1737. }
  1738. /// <summary>
  1739. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1740. /// </summary>
  1741. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1742. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1743. /// <param name="selector">A transform function to apply to each element.</param>
  1744. /// <returns>
  1745. /// The population standard deviation of the sequence of values.
  1746. /// </returns>
  1747. public static double StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector)
  1748. {
  1749. return source.Provider.Execute<double>(
  1750. Expression.Call(
  1751. GetMethodInfo(StandardDeviationSample, source, selector),
  1752. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1753. Expression.Quote(selector)));
  1754. }
  1755. /// <summary>
  1756. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1757. /// </summary>
  1758. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1759. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1760. /// <param name="selector">A transform function to apply to each element.</param>
  1761. /// <returns>
  1762. /// The population standard deviation of the sequence of values.
  1763. /// </returns>
  1764. public static double? StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector)
  1765. {
  1766. return source.Provider.Execute<double?>(
  1767. Expression.Call(
  1768. GetMethodInfo(StandardDeviationSample, source, selector),
  1769. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1770. Expression.Quote(selector)));
  1771. }
  1772. /// <summary>
  1773. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1774. /// </summary>
  1775. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1776. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1777. /// <param name="selector">A transform function to apply to each element.</param>
  1778. /// <returns>
  1779. /// The population standard deviation of the sequence of values.
  1780. /// </returns>
  1781. public static double StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector)
  1782. {
  1783. return source.Provider.Execute<double>(
  1784. Expression.Call(
  1785. GetMethodInfo(StandardDeviationSample, source, selector),
  1786. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1787. Expression.Quote(selector)));
  1788. }
  1789. /// <summary>
  1790. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1791. /// </summary>
  1792. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1793. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1794. /// <param name="selector">A transform function to apply to each element.</param>
  1795. /// <returns>
  1796. /// The population standard deviation of the sequence of values.
  1797. /// </returns>
  1798. public static double? StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector)
  1799. {
  1800. return source.Provider.Execute<double?>(
  1801. Expression.Call(
  1802. GetMethodInfo(StandardDeviationSample, source, selector),
  1803. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1804. Expression.Quote(selector)));
  1805. }
  1806. /// <summary>
  1807. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1808. /// </summary>
  1809. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1810. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1811. /// <param name="selector">A transform function to apply to each element.</param>
  1812. /// <returns>
  1813. /// The population standard deviation of the sequence of values.
  1814. /// </returns>
  1815. public static float StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector)
  1816. {
  1817. return source.Provider.Execute<float>(
  1818. Expression.Call(
  1819. GetMethodInfo(StandardDeviationSample, source, selector),
  1820. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1821. Expression.Quote(selector)));
  1822. }
  1823. /// <summary>
  1824. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1825. /// </summary>
  1826. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1827. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1828. /// <param name="selector">A transform function to apply to each element.</param>
  1829. /// <returns>
  1830. /// The population standard deviation of the sequence of values.
  1831. /// </returns>
  1832. public static float? StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector)
  1833. {
  1834. return source.Provider.Execute<float?>(
  1835. Expression.Call(
  1836. GetMethodInfo(StandardDeviationSample, source, selector),
  1837. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1838. Expression.Quote(selector)));
  1839. }
  1840. /// <summary>
  1841. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1842. /// </summary>
  1843. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1844. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1845. /// <param name="selector">A transform function to apply to each element.</param>
  1846. /// <returns>
  1847. /// The population standard deviation of the sequence of values.
  1848. /// </returns>
  1849. public static double StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector)
  1850. {
  1851. return source.Provider.Execute<double>(
  1852. Expression.Call(
  1853. GetMethodInfo(StandardDeviationSample, source, selector),
  1854. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1855. Expression.Quote(selector)));
  1856. }
  1857. /// <summary>
  1858. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1859. /// </summary>
  1860. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1861. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1862. /// <param name="selector">A transform function to apply to each element.</param>
  1863. /// <returns>
  1864. /// The population standard deviation of the sequence of values.
  1865. /// </returns>
  1866. public static double? StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector)
  1867. {
  1868. return source.Provider.Execute<double?>(
  1869. Expression.Call(
  1870. GetMethodInfo(StandardDeviationSample, source, selector),
  1871. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1872. Expression.Quote(selector)));
  1873. }
  1874. /// <summary>
  1875. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1876. /// </summary>
  1877. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1878. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1879. /// <param name="selector">A transform function to apply to each element.</param>
  1880. /// <returns>
  1881. /// The population standard deviation of the sequence of values.
  1882. /// </returns>
  1883. public static decimal StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector)
  1884. {
  1885. return source.Provider.Execute<decimal>(
  1886. Expression.Call(
  1887. GetMethodInfo(StandardDeviationSample, source, selector),
  1888. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1889. Expression.Quote(selector)));
  1890. }
  1891. /// <summary>
  1892. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  1893. /// </summary>
  1894. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  1895. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1896. /// <param name="selector">A transform function to apply to each element.</param>
  1897. /// <returns>
  1898. /// The population standard deviation of the sequence of values.
  1899. /// </returns>
  1900. public static decimal? StandardDeviationSample<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector)
  1901. {
  1902. return source.Provider.Execute<decimal?>(
  1903. Expression.Call(
  1904. GetMethodInfo(StandardDeviationSample, source, selector),
  1905. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  1906. Expression.Quote(selector)));
  1907. }
  1908. /// <summary>
  1909. /// Computes the sample standard deviation of a sequence of values.
  1910. /// </summary>
  1911. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1912. /// <param name="cancellationToken">The cancellation token.</param>
  1913. /// <returns>
  1914. /// The population standard deviation of the sequence of values.
  1915. /// </returns>
  1916. public static Task<double> StandardDeviationSampleAsync(this IMongoQueryable<int> source, CancellationToken cancellationToken = default(CancellationToken))
  1917. {
  1918. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1919. Expression.Call(
  1920. GetMethodInfo(StandardDeviationSample, source),
  1921. Expression.Convert(source.Expression, typeof(IMongoQueryable<int>))),
  1922. cancellationToken);
  1923. }
  1924. /// <summary>
  1925. /// Computes the sample standard deviation of a sequence of values.
  1926. /// </summary>
  1927. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1928. /// <param name="cancellationToken">The cancellation token.</param>
  1929. /// <returns>
  1930. /// The population standard deviation of the sequence of values.
  1931. /// </returns>
  1932. public static Task<double?> StandardDeviationSampleAsync(this IMongoQueryable<int?> source, CancellationToken cancellationToken = default(CancellationToken))
  1933. {
  1934. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1935. Expression.Call(
  1936. GetMethodInfo(StandardDeviationSample, source),
  1937. Expression.Convert(source.Expression, typeof(IMongoQueryable<int?>))),
  1938. cancellationToken);
  1939. }
  1940. /// <summary>
  1941. /// Computes the sample standard deviation of a sequence of values.
  1942. /// </summary>
  1943. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1944. /// <param name="cancellationToken">The cancellation token.</param>
  1945. /// <returns>
  1946. /// The population standard deviation of the sequence of values.
  1947. /// </returns>
  1948. public static Task<double> StandardDeviationSampleAsync(this IMongoQueryable<long> source, CancellationToken cancellationToken = default(CancellationToken))
  1949. {
  1950. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  1951. Expression.Call(
  1952. GetMethodInfo(StandardDeviationSample, source),
  1953. Expression.Convert(source.Expression, typeof(IMongoQueryable<long>))),
  1954. cancellationToken);
  1955. }
  1956. /// <summary>
  1957. /// Computes the sample standard deviation of a sequence of values.
  1958. /// </summary>
  1959. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1960. /// <param name="cancellationToken">The cancellation token.</param>
  1961. /// <returns>
  1962. /// The population standard deviation of the sequence of values.
  1963. /// </returns>
  1964. public static Task<double?> StandardDeviationSampleAsync(this IMongoQueryable<long?> source, CancellationToken cancellationToken = default(CancellationToken))
  1965. {
  1966. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  1967. Expression.Call(
  1968. GetMethodInfo(StandardDeviationSample, source),
  1969. Expression.Convert(source.Expression, typeof(IMongoQueryable<long?>))),
  1970. cancellationToken);
  1971. }
  1972. /// <summary>
  1973. /// Computes the sample standard deviation of a sequence of values.
  1974. /// </summary>
  1975. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1976. /// <param name="cancellationToken">The cancellation token.</param>
  1977. /// <returns>
  1978. /// The population standard deviation of the sequence of values.
  1979. /// </returns>
  1980. public static Task<float> StandardDeviationSampleAsync(this IMongoQueryable<float> source, CancellationToken cancellationToken = default(CancellationToken))
  1981. {
  1982. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  1983. Expression.Call(
  1984. GetMethodInfo(StandardDeviationSample, source),
  1985. Expression.Convert(source.Expression, typeof(IMongoQueryable<float>))),
  1986. cancellationToken);
  1987. }
  1988. /// <summary>
  1989. /// Computes the sample standard deviation of a sequence of values.
  1990. /// </summary>
  1991. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  1992. /// <param name="cancellationToken">The cancellation token.</param>
  1993. /// <returns>
  1994. /// The population standard deviation of the sequence of values.
  1995. /// </returns>
  1996. public static Task<float?> StandardDeviationSampleAsync(this IMongoQueryable<float?> source, CancellationToken cancellationToken = default(CancellationToken))
  1997. {
  1998. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  1999. Expression.Call(
  2000. GetMethodInfo(StandardDeviationSample, source),
  2001. Expression.Convert(source.Expression, typeof(IMongoQueryable<float?>))),
  2002. cancellationToken);
  2003. }
  2004. /// <summary>
  2005. /// Computes the sample standard deviation of a sequence of values.
  2006. /// </summary>
  2007. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2008. /// <param name="cancellationToken">The cancellation token.</param>
  2009. /// <returns>
  2010. /// The population standard deviation of the sequence of values.
  2011. /// </returns>
  2012. public static Task<double> StandardDeviationSampleAsync(this IMongoQueryable<double> source, CancellationToken cancellationToken = default(CancellationToken))
  2013. {
  2014. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2015. Expression.Call(
  2016. GetMethodInfo(StandardDeviationSample, source),
  2017. Expression.Convert(source.Expression, typeof(IMongoQueryable<double>))),
  2018. cancellationToken);
  2019. }
  2020. /// <summary>
  2021. /// Computes the sample standard deviation of a sequence of values.
  2022. /// </summary>
  2023. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2024. /// <param name="cancellationToken">The cancellation token.</param>
  2025. /// <returns>
  2026. /// The population standard deviation of the sequence of values.
  2027. /// </returns>
  2028. public static Task<double?> StandardDeviationSampleAsync(this IMongoQueryable<double?> source, CancellationToken cancellationToken = default(CancellationToken))
  2029. {
  2030. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2031. Expression.Call(
  2032. GetMethodInfo(StandardDeviationSample, source),
  2033. Expression.Convert(source.Expression, typeof(IMongoQueryable<double?>))),
  2034. cancellationToken);
  2035. }
  2036. /// <summary>
  2037. /// Computes the sample standard deviation of a sequence of values.
  2038. /// </summary>
  2039. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2040. /// <param name="cancellationToken">The cancellation token.</param>
  2041. /// <returns>
  2042. /// The population standard deviation of the sequence of values.
  2043. /// </returns>
  2044. public static Task<decimal> StandardDeviationSampleAsync(this IMongoQueryable<decimal> source, CancellationToken cancellationToken = default(CancellationToken))
  2045. {
  2046. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  2047. Expression.Call(
  2048. GetMethodInfo(StandardDeviationSample, source),
  2049. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal>))),
  2050. cancellationToken);
  2051. }
  2052. /// <summary>
  2053. /// Computes the sample standard deviation of a sequence of values.
  2054. /// </summary>
  2055. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2056. /// <param name="cancellationToken">The cancellation token.</param>
  2057. /// <returns>
  2058. /// The population standard deviation of the sequence of values.
  2059. /// </returns>
  2060. public static Task<decimal?> StandardDeviationSampleAsync(this IMongoQueryable<decimal?> source, CancellationToken cancellationToken = default(CancellationToken))
  2061. {
  2062. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  2063. Expression.Call(
  2064. GetMethodInfo(StandardDeviationSample, source),
  2065. Expression.Convert(source.Expression, typeof(IMongoQueryable<decimal?>))),
  2066. cancellationToken);
  2067. }
  2068. /// <summary>
  2069. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2070. /// </summary>
  2071. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2072. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2073. /// <param name="selector">A transform function to apply to each element.</param>
  2074. /// <param name="cancellationToken">The cancellation token.</param>
  2075. /// <returns>
  2076. /// The population standard deviation of the sequence of values.
  2077. /// </returns>
  2078. public static Task<double> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2079. {
  2080. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2081. Expression.Call(
  2082. GetMethodInfo(StandardDeviationSample, source, selector),
  2083. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2084. Expression.Quote(selector)),
  2085. cancellationToken);
  2086. }
  2087. /// <summary>
  2088. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2089. /// </summary>
  2090. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2091. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2092. /// <param name="selector">A transform function to apply to each element.</param>
  2093. /// <param name="cancellationToken">The cancellation token.</param>
  2094. /// <returns>
  2095. /// The population standard deviation of the sequence of values.
  2096. /// </returns>
  2097. public static Task<double?> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2098. {
  2099. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2100. Expression.Call(
  2101. GetMethodInfo(StandardDeviationSample, source, selector),
  2102. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2103. Expression.Quote(selector)),
  2104. cancellationToken);
  2105. }
  2106. /// <summary>
  2107. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2108. /// </summary>
  2109. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2110. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2111. /// <param name="selector">A transform function to apply to each element.</param>
  2112. /// <param name="cancellationToken">The cancellation token.</param>
  2113. /// <returns>
  2114. /// The population standard deviation of the sequence of values.
  2115. /// </returns>
  2116. public static Task<double> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2117. {
  2118. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2119. Expression.Call(
  2120. GetMethodInfo(StandardDeviationSample, source, selector),
  2121. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2122. Expression.Quote(selector)),
  2123. cancellationToken);
  2124. }
  2125. /// <summary>
  2126. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2127. /// </summary>
  2128. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2129. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2130. /// <param name="selector">A transform function to apply to each element.</param>
  2131. /// <param name="cancellationToken">The cancellation token.</param>
  2132. /// <returns>
  2133. /// The population standard deviation of the sequence of values.
  2134. /// </returns>
  2135. public static Task<double?> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2136. {
  2137. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2138. Expression.Call(
  2139. GetMethodInfo(StandardDeviationSample, source, selector),
  2140. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2141. Expression.Quote(selector)),
  2142. cancellationToken);
  2143. }
  2144. /// <summary>
  2145. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2146. /// </summary>
  2147. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2148. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2149. /// <param name="selector">A transform function to apply to each element.</param>
  2150. /// <param name="cancellationToken">The cancellation token.</param>
  2151. /// <returns>
  2152. /// The population standard deviation of the sequence of values.
  2153. /// </returns>
  2154. public static Task<float> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2155. {
  2156. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  2157. Expression.Call(
  2158. GetMethodInfo(StandardDeviationSample, source, selector),
  2159. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2160. Expression.Quote(selector)),
  2161. cancellationToken);
  2162. }
  2163. /// <summary>
  2164. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2165. /// </summary>
  2166. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2167. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2168. /// <param name="selector">A transform function to apply to each element.</param>
  2169. /// <param name="cancellationToken">The cancellation token.</param>
  2170. /// <returns>
  2171. /// The population standard deviation of the sequence of values.
  2172. /// </returns>
  2173. public static Task<float?> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2174. {
  2175. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  2176. Expression.Call(
  2177. GetMethodInfo(StandardDeviationSample, source, selector),
  2178. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2179. Expression.Quote(selector)),
  2180. cancellationToken);
  2181. }
  2182. /// <summary>
  2183. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2184. /// </summary>
  2185. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2186. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2187. /// <param name="selector">A transform function to apply to each element.</param>
  2188. /// <param name="cancellationToken">The cancellation token.</param>
  2189. /// <returns>
  2190. /// The population standard deviation of the sequence of values.
  2191. /// </returns>
  2192. public static Task<double> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2193. {
  2194. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2195. Expression.Call(
  2196. GetMethodInfo(StandardDeviationSample, source, selector),
  2197. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2198. Expression.Quote(selector)),
  2199. cancellationToken);
  2200. }
  2201. /// <summary>
  2202. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2203. /// </summary>
  2204. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2205. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2206. /// <param name="selector">A transform function to apply to each element.</param>
  2207. /// <param name="cancellationToken">The cancellation token.</param>
  2208. /// <returns>
  2209. /// The population standard deviation of the sequence of values.
  2210. /// </returns>
  2211. public static Task<double?> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2212. {
  2213. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2214. Expression.Call(
  2215. GetMethodInfo(StandardDeviationSample, source, selector),
  2216. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2217. Expression.Quote(selector)),
  2218. cancellationToken);
  2219. }
  2220. /// <summary>
  2221. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2222. /// </summary>
  2223. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2224. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2225. /// <param name="selector">A transform function to apply to each element.</param>
  2226. /// <param name="cancellationToken">The cancellation token.</param>
  2227. /// <returns>
  2228. /// The population standard deviation of the sequence of values.
  2229. /// </returns>
  2230. public static Task<decimal> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2231. {
  2232. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  2233. Expression.Call(
  2234. GetMethodInfo(StandardDeviationSample, source, selector),
  2235. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2236. Expression.Quote(selector)),
  2237. cancellationToken);
  2238. }
  2239. /// <summary>
  2240. /// Computes the sample standard deviation of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
  2241. /// </summary>
  2242. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2243. /// <param name="source">A sequence of values to calculate the population standard deviation of.</param>
  2244. /// <param name="selector">A transform function to apply to each element.</param>
  2245. /// <param name="cancellationToken">The cancellation token.</param>
  2246. /// <returns>
  2247. /// The population standard deviation of the sequence of values.
  2248. /// </returns>
  2249. public static Task<decimal?> StandardDeviationSampleAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2250. {
  2251. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  2252. Expression.Call(
  2253. GetMethodInfo(StandardDeviationSample, source, selector),
  2254. Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
  2255. Expression.Quote(selector)),
  2256. cancellationToken);
  2257. }
  2258. /// <summary>
  2259. /// Computes the sum of a sequence of <see cref="Decimal"/> values.
  2260. /// </summary>
  2261. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2262. /// <param name="cancellationToken">The cancellation token.</param>
  2263. /// <returns>The sum of the values in the sequence.</returns>
  2264. public static Task<decimal> SumAsync(this IMongoQueryable<decimal> source, CancellationToken cancellationToken = default(CancellationToken))
  2265. {
  2266. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  2267. Expression.Call(
  2268. GetMethodInfo<IQueryable<decimal>, decimal>(Queryable.Sum, source),
  2269. source.Expression),
  2270. cancellationToken);
  2271. }
  2272. /// <summary>
  2273. /// Computes the sum of a sequence of <see cref="Nullable{Decimal}"/> values.
  2274. /// </summary>
  2275. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2276. /// <param name="cancellationToken">The cancellation token.</param>
  2277. /// <returns>The sum of the values in the sequence.</returns>
  2278. public static Task<decimal?> SumAsync(this IMongoQueryable<decimal?> source, CancellationToken cancellationToken = default(CancellationToken))
  2279. {
  2280. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  2281. Expression.Call(
  2282. GetMethodInfo<IQueryable<decimal?>, decimal?>(Queryable.Sum, source),
  2283. source.Expression),
  2284. cancellationToken);
  2285. }
  2286. /// <summary>
  2287. /// Computes the sum of a sequence of <see cref="Double"/> values.
  2288. /// </summary>
  2289. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2290. /// <param name="cancellationToken">The cancellation token.</param>
  2291. /// <returns>The sum of the values in the sequence.</returns>
  2292. public static Task<double> SumAsync(this IMongoQueryable<double> source, CancellationToken cancellationToken = default(CancellationToken))
  2293. {
  2294. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2295. Expression.Call(
  2296. GetMethodInfo<IQueryable<double>, double>(Queryable.Sum, source),
  2297. source.Expression),
  2298. cancellationToken);
  2299. }
  2300. /// <summary>
  2301. /// Computes the sum of a sequence of <see cref="Nullable{Double}"/> values.
  2302. /// </summary>
  2303. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2304. /// <param name="cancellationToken">The cancellation token.</param>
  2305. /// <returns>The sum of the values in the sequence.</returns>
  2306. public static Task<double?> SumAsync(this IMongoQueryable<double?> source, CancellationToken cancellationToken = default(CancellationToken))
  2307. {
  2308. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2309. Expression.Call(
  2310. GetMethodInfo<IQueryable<double?>, double?>(Queryable.Sum, source),
  2311. source.Expression),
  2312. cancellationToken);
  2313. }
  2314. /// <summary>
  2315. /// Computes the sum of a sequence of <see cref="Single"/> values.
  2316. /// </summary>
  2317. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2318. /// <param name="cancellationToken">The cancellation token.</param>
  2319. /// <returns>The sum of the values in the sequence.</returns>
  2320. public static Task<float> SumAsync(this IMongoQueryable<float> source, CancellationToken cancellationToken = default(CancellationToken))
  2321. {
  2322. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  2323. Expression.Call(
  2324. GetMethodInfo<IQueryable<float>, float>(Queryable.Sum, source),
  2325. source.Expression),
  2326. cancellationToken);
  2327. }
  2328. /// <summary>
  2329. /// Computes the sum of a sequence of <see cref="Nullable{Single}"/> values.
  2330. /// </summary>
  2331. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2332. /// <param name="cancellationToken">The cancellation token.</param>
  2333. /// <returns>The sum of the values in the sequence.</returns>
  2334. public static Task<float?> SumAsync(this IMongoQueryable<float?> source, CancellationToken cancellationToken = default(CancellationToken))
  2335. {
  2336. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  2337. Expression.Call(
  2338. GetMethodInfo<IQueryable<float?>, float?>(Queryable.Sum, source),
  2339. source.Expression),
  2340. cancellationToken);
  2341. }
  2342. /// <summary>
  2343. /// Computes the sum of a sequence of <see cref="Int32"/> values.
  2344. /// </summary>
  2345. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2346. /// <param name="cancellationToken">The cancellation token.</param>
  2347. /// <returns>The sum of the values in the sequence.</returns>
  2348. public static Task<int> SumAsync(this IMongoQueryable<int> source, CancellationToken cancellationToken = default(CancellationToken))
  2349. {
  2350. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int>(
  2351. Expression.Call(
  2352. GetMethodInfo<IQueryable<int>, int>(Queryable.Sum, source),
  2353. source.Expression),
  2354. cancellationToken);
  2355. }
  2356. /// <summary>
  2357. /// Computes the sum of a sequence of <see cref="Nullable{Int32}"/> values.
  2358. /// </summary>
  2359. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2360. /// <param name="cancellationToken">The cancellation token.</param>
  2361. /// <returns>The sum of the values in the sequence.</returns>
  2362. public static Task<int?> SumAsync(this IMongoQueryable<int?> source, CancellationToken cancellationToken = default(CancellationToken))
  2363. {
  2364. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int?>(
  2365. Expression.Call(
  2366. GetMethodInfo<IQueryable<int?>, int?>(Queryable.Sum, source),
  2367. source.Expression),
  2368. cancellationToken);
  2369. }
  2370. /// <summary>
  2371. /// Computes the sum of a sequence of <see cref="Int64"/> values.
  2372. /// </summary>
  2373. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2374. /// <param name="cancellationToken">The cancellation token.</param>
  2375. /// <returns>The sum of the values in the sequence.</returns>
  2376. public static Task<long> SumAsync(this IMongoQueryable<long> source, CancellationToken cancellationToken = default(CancellationToken))
  2377. {
  2378. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long>(
  2379. Expression.Call(
  2380. GetMethodInfo<IQueryable<long>, long>(Queryable.Sum, source),
  2381. source.Expression),
  2382. cancellationToken);
  2383. }
  2384. /// <summary>
  2385. /// Computes the sum of a sequence of <see cref="Nullable{Int64}"/> values.
  2386. /// </summary>
  2387. /// <param name="source">A sequence of values to calculate the sum of.</param>
  2388. /// <param name="cancellationToken">The cancellation token.</param>
  2389. /// <returns>The sum of the values in the sequence.</returns>
  2390. public static Task<long?> SumAsync(this IMongoQueryable<long?> source, CancellationToken cancellationToken = default(CancellationToken))
  2391. {
  2392. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long?>(
  2393. Expression.Call(
  2394. GetMethodInfo<IQueryable<long?>, long?>(Queryable.Sum, source),
  2395. source.Expression),
  2396. cancellationToken);
  2397. }
  2398. /// <summary>
  2399. /// Computes the sum of the sequence of <see cref="Decimal" /> values that is obtained
  2400. /// by invoking a projection function on each element of the input sequence.
  2401. /// </summary>
  2402. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2403. /// <param name="source">A sequence of values.</param>
  2404. /// <param name="selector">A projection function to apply to each element.</param>
  2405. /// <param name="cancellationToken">The cancellation token.</param>
  2406. /// <returns>
  2407. /// The sum of the projected values.
  2408. /// </returns>
  2409. public static Task<decimal> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2410. {
  2411. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal>(
  2412. Expression.Call(
  2413. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, decimal>>, decimal>(Queryable.Sum, source, selector),
  2414. source.Expression,
  2415. Expression.Quote(selector)),
  2416. cancellationToken);
  2417. }
  2418. /// <summary>
  2419. /// Computes the sum of the sequence of <see cref="Nullable{Decimal}" /> values that is obtained
  2420. /// by invoking a projection function on each element of the input sequence.
  2421. /// </summary>
  2422. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2423. /// <param name="source">A sequence of values.</param>
  2424. /// <param name="selector">A projection function to apply to each element.</param>
  2425. /// <param name="cancellationToken">The cancellation token.</param>
  2426. /// <returns>
  2427. /// The sum of the projected values.
  2428. /// </returns>
  2429. public static Task<decimal?> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2430. {
  2431. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<decimal?>(
  2432. Expression.Call(
  2433. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, decimal?>>, decimal?>(Queryable.Sum, source, selector),
  2434. source.Expression,
  2435. Expression.Quote(selector)),
  2436. cancellationToken);
  2437. }
  2438. /// <summary>
  2439. /// Computes the sum of the sequence of <see cref="Double" /> values that is obtained
  2440. /// by invoking a projection function on each element of the input sequence.
  2441. /// </summary>
  2442. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2443. /// <param name="source">A sequence of values.</param>
  2444. /// <param name="selector">A projection function to apply to each element.</param>
  2445. /// <param name="cancellationToken">The cancellation token.</param>
  2446. /// <returns>
  2447. /// The sum of the projected values.
  2448. /// </returns>
  2449. public static Task<double> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2450. {
  2451. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double>(
  2452. Expression.Call(
  2453. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, double>>, double>(Queryable.Sum, source, selector),
  2454. source.Expression,
  2455. Expression.Quote(selector)),
  2456. cancellationToken);
  2457. }
  2458. /// <summary>
  2459. /// Computes the sum of the sequence of <see cref="Nullable{Double}" /> values that is obtained
  2460. /// by invoking a projection function on each element of the input sequence.
  2461. /// </summary>
  2462. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2463. /// <param name="source">A sequence of values.</param>
  2464. /// <param name="selector">A projection function to apply to each element.</param>
  2465. /// <param name="cancellationToken">The cancellation token.</param>
  2466. /// <returns>
  2467. /// The sum of the projected values.
  2468. /// </returns>
  2469. public static Task<double?> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2470. {
  2471. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<double?>(
  2472. Expression.Call(
  2473. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, double?>>, double?>(Queryable.Sum, source, selector),
  2474. source.Expression,
  2475. Expression.Quote(selector)),
  2476. cancellationToken);
  2477. }
  2478. /// <summary>
  2479. /// Computes the sum of the sequence of <see cref="Single" /> values that is obtained
  2480. /// by invoking a projection function on each element of the input sequence.
  2481. /// </summary>
  2482. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2483. /// <param name="source">A sequence of values.</param>
  2484. /// <param name="selector">A projection function to apply to each element.</param>
  2485. /// <param name="cancellationToken">The cancellation token.</param>
  2486. /// <returns>
  2487. /// The sum of the projected values.
  2488. /// </returns>
  2489. public static Task<float> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2490. {
  2491. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float>(
  2492. Expression.Call(
  2493. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, float>>, float>(Queryable.Sum, source, selector),
  2494. source.Expression,
  2495. Expression.Quote(selector)),
  2496. cancellationToken);
  2497. }
  2498. /// <summary>
  2499. /// Computes the sum of the sequence of <see cref="Nullable{Single}" /> values that is obtained
  2500. /// by invoking a projection function on each element of the input sequence.
  2501. /// </summary>
  2502. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2503. /// <param name="source">A sequence of values.</param>
  2504. /// <param name="selector">A projection function to apply to each element.</param>
  2505. /// <param name="cancellationToken">The cancellation token.</param>
  2506. /// <returns>
  2507. /// The sum of the projected values.
  2508. /// </returns>
  2509. public static Task<float?> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2510. {
  2511. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<float?>(
  2512. Expression.Call(
  2513. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, float?>>, float?>(Queryable.Sum, source, selector),
  2514. source.Expression,
  2515. Expression.Quote(selector)),
  2516. cancellationToken);
  2517. }
  2518. /// <summary>
  2519. /// Computes the sum of the sequence of <see cref="Int32" /> values that is obtained
  2520. /// by invoking a projection function on each element of the input sequence.
  2521. /// </summary>
  2522. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2523. /// <param name="source">A sequence of values.</param>
  2524. /// <param name="selector">A projection function to apply to each element.</param>
  2525. /// <param name="cancellationToken">The cancellation token.</param>
  2526. /// <returns>
  2527. /// The sum of the projected values.
  2528. /// </returns>
  2529. public static Task<int> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2530. {
  2531. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int>(
  2532. Expression.Call(
  2533. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, int>>, int>(Queryable.Sum, source, selector),
  2534. source.Expression,
  2535. Expression.Quote(selector)),
  2536. cancellationToken);
  2537. }
  2538. /// <summary>
  2539. /// Computes the sum of the sequence of <see cref="Nullable{Int32}" /> values that is obtained
  2540. /// by invoking a projection function on each element of the input sequence.
  2541. /// </summary>
  2542. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2543. /// <param name="source">A sequence of values.</param>
  2544. /// <param name="selector">A projection function to apply to each element.</param>
  2545. /// <param name="cancellationToken">The cancellation token.</param>
  2546. /// <returns>
  2547. /// The sum of the projected values.
  2548. /// </returns>
  2549. public static Task<int?> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2550. {
  2551. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<int?>(
  2552. Expression.Call(
  2553. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, int?>>, int?>(Queryable.Sum, source, selector),
  2554. source.Expression,
  2555. Expression.Quote(selector)),
  2556. cancellationToken);
  2557. }
  2558. /// <summary>
  2559. /// Computes the sum of the sequence of <see cref="Int64" /> values that is obtained
  2560. /// by invoking a projection function on each element of the input sequence.
  2561. /// </summary>
  2562. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2563. /// <param name="source">A sequence of values.</param>
  2564. /// <param name="selector">A projection function to apply to each element.</param>
  2565. /// <param name="cancellationToken">The cancellation token.</param>
  2566. /// <returns>
  2567. /// The sum of the projected values.
  2568. /// </returns>
  2569. public static Task<long> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2570. {
  2571. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long>(
  2572. Expression.Call(
  2573. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, long>>, long>(Queryable.Sum, source, selector),
  2574. source.Expression,
  2575. Expression.Quote(selector)),
  2576. cancellationToken);
  2577. }
  2578. /// <summary>
  2579. /// Computes the sum of the sequence of <see cref="Nullable{Int64}" /> values that is obtained
  2580. /// by invoking a projection function on each element of the input sequence.
  2581. /// </summary>
  2582. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2583. /// <param name="source">A sequence of values.</param>
  2584. /// <param name="selector">A projection function to apply to each element.</param>
  2585. /// <param name="cancellationToken">The cancellation token.</param>
  2586. /// <returns>
  2587. /// The sum of the projected values.
  2588. /// </returns>
  2589. public static Task<long?> SumAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default(CancellationToken))
  2590. {
  2591. return ((IMongoQueryProvider)source.Provider).ExecuteAsync<long?>(
  2592. Expression.Call(
  2593. GetMethodInfo<IQueryable<TSource>, Expression<Func<TSource, long?>>, long?>(Queryable.Sum, source, selector),
  2594. source.Expression,
  2595. Expression.Quote(selector)),
  2596. cancellationToken);
  2597. }
  2598. /// <summary>
  2599. /// Returns a specified number of contiguous elements from the start of a sequence.
  2600. /// </summary>
  2601. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2602. /// <param name="source">The sequence to return elements from.</param>
  2603. /// <param name="count">The number of elements to return.</param>
  2604. /// <returns>
  2605. /// An <see cref="IMongoQueryable{TSource}"/> that contains the specified number of elements
  2606. /// from the start of source.
  2607. /// </returns>
  2608. public static IMongoQueryable<TSource> Take<TSource>(this IMongoQueryable<TSource> source, int count)
  2609. {
  2610. return (IMongoQueryable<TSource>)Queryable.Take(source, count);
  2611. }
  2612. /// <summary>
  2613. /// Performs a subsequent ordering of the elements in a sequence in ascending
  2614. /// order according to a key.
  2615. /// </summary>
  2616. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2617. /// <typeparam name="TKey">The type of the key returned by the function that is represented by keySelector.</typeparam>
  2618. /// <param name="source">A sequence of values to order.</param>
  2619. /// <param name="keySelector">A function to extract a key from an element.</param>
  2620. /// <returns>
  2621. /// An <see cref="IOrderedMongoQueryable{TSource}"/> whose elements are sorted according to a key.
  2622. /// </returns>
  2623. public static IOrderedMongoQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  2624. {
  2625. return (IOrderedMongoQueryable<TSource>)Queryable.ThenBy(source, keySelector);
  2626. }
  2627. /// <summary>
  2628. /// Performs a subsequent ordering of the elements in a sequence in descending
  2629. /// order according to a key.
  2630. /// </summary>
  2631. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2632. /// <typeparam name="TKey">The type of the key returned by the function that is represented by keySelector.</typeparam>
  2633. /// <param name="source">A sequence of values to order.</param>
  2634. /// <param name="keySelector">A function to extract a key from an element.</param>
  2635. /// <returns>
  2636. /// An <see cref="IOrderedMongoQueryable{TSource}"/> whose elements are sorted in descending order according to a key.
  2637. /// </returns>
  2638. public static IOrderedMongoQueryable<TSource> ThenByDescending<TSource, TKey>(this IOrderedMongoQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  2639. {
  2640. return (IOrderedMongoQueryable<TSource>)Queryable.ThenByDescending(source, keySelector);
  2641. }
  2642. /// <summary>
  2643. /// Filters a sequence of values based on a predicate.
  2644. /// </summary>
  2645. /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
  2646. /// <param name="source">An <see cref="IMongoQueryable{TSource}"/> to return elements from.</param>
  2647. /// <param name="predicate">A function to test each element for a condition.</param>
  2648. /// <returns>
  2649. /// An <see cref="IMongoQueryable{TSource}"/> that contains elements from the input sequence
  2650. /// that satisfy the condition specified by predicate.
  2651. /// </returns>
  2652. public static IMongoQueryable<TSource> Where<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
  2653. {
  2654. return (IMongoQueryable<TSource>)Queryable.Where(source, predicate);
  2655. }
  2656. private static MethodInfo GetMethodInfo<T1, T2>(Func<T1, T2> f, T1 unused)
  2657. {
  2658. return f.GetMethodInfo();
  2659. }
  2660. private static MethodInfo GetMethodInfo<T1, T2, T3>(Func<T1, T2, T3> f, T1 unused1, T2 unused2)
  2661. {
  2662. return f.GetMethodInfo();
  2663. }
  2664. }
  2665. }