1 //--------------------------------------------------------------------- 2 // <copyright file="EdmFunctions.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 // 6 // @owner Microsoft 7 // @backupOwner Microsoft 8 //--------------------------------------------------------------------- 9 10 namespace System.Data.Common.CommandTrees.ExpressionBuilder 11 { 12 using System; 13 using System.Collections.Generic; 14 using System.Data.Entity; 15 using System.Data.Metadata.Edm; 16 using System.Diagnostics; 17 18 /// <summary> 19 /// Provides an API to construct <see cref="DbExpression"/>s that invoke canonical EDM functions, and allows that API to be accessed as extension methods on the expression type itself. 20 /// </summary> 21 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")] 22 public static class EdmFunctions 23 { 24 #region Private Implementation 25 ResolveCanonicalFunction(string functionName, TypeUsage[] argumentTypes)26 private static EdmFunction ResolveCanonicalFunction(string functionName, TypeUsage[] argumentTypes) 27 { 28 Debug.Assert(!string.IsNullOrEmpty(functionName), "Function name must not be null"); 29 30 List<EdmFunction> functions = new List<EdmFunction>( 31 System.Linq.Enumerable.Where( 32 EdmProviderManifest.Instance.GetStoreFunctions(), 33 func => string.Equals(func.Name, functionName, StringComparison.Ordinal)) 34 ); 35 36 EdmFunction foundFunction = null; 37 bool ambiguous = false; 38 if (functions.Count > 0) 39 { 40 foundFunction = EntitySql.FunctionOverloadResolver.ResolveFunctionOverloads(functions, argumentTypes, false, out ambiguous); 41 if (ambiguous) 42 { 43 throw EntityUtil.Argument(Strings.Cqt_Function_CanonicalFunction_AmbiguousMatch(functionName)); 44 } 45 } 46 47 if (foundFunction == null) 48 { 49 throw EntityUtil.Argument(Strings.Cqt_Function_CanonicalFunction_NotFound(functionName)); 50 } 51 52 return foundFunction; 53 } 54 InvokeCanonicalFunction(string functionName, params DbExpression[] arguments)55 internal static DbFunctionExpression InvokeCanonicalFunction(string functionName, params DbExpression[] arguments) 56 { 57 TypeUsage[] argumentTypes = new TypeUsage[arguments.Length]; 58 for (int idx = 0; idx < arguments.Length; idx++) 59 { 60 Debug.Assert(arguments[idx] != null, "Ensure arguments are non-null before calling InvokeCanonicalFunction"); 61 argumentTypes[idx] = arguments[idx].ResultType; 62 } 63 64 EdmFunction foundFunction = ResolveCanonicalFunction(functionName, argumentTypes); 65 return DbExpressionBuilder.Invoke(foundFunction, arguments); 66 } 67 68 #endregion 69 70 #region Aggregate functions - Average, Count, LongCount, Max, Min, Sum, StDev, StDevP, Var, VarP 71 72 /// <summary> 73 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Avg' function over the 74 /// specified collection. The result type of the expression is the same as the element type of the collection. 75 /// </summary> 76 /// <param name="collection">An expression that specifies the collection from which the average value should be computed</param> 77 /// <returns>A new DbFunctionExpression that produces the average value.</returns> 78 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 79 /// <exception cref="ArgumentException">No overload of the canonical 'Avg' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Average(this DbExpression collection)80 public static DbFunctionExpression Average(this DbExpression collection) 81 { 82 EntityUtil.CheckArgumentNull(collection, "collection"); 83 return InvokeCanonicalFunction("Avg", collection); 84 } 85 86 /// <summary> 87 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Count' function over the 88 /// specified collection. The result type of the expression is Edm.Int32. 89 /// </summary> 90 /// <param name="collection">An expression that specifies the collection over which the count value should be computed.</param> 91 /// <returns>A new DbFunctionExpression that produces the count value.</returns> 92 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 93 /// <exception cref="ArgumentException">No overload of the canonical 'Count' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Count(this DbExpression collection)94 public static DbFunctionExpression Count(this DbExpression collection) 95 { 96 EntityUtil.CheckArgumentNull(collection, "collection"); 97 return InvokeCanonicalFunction("Count", collection); 98 } 99 100 /// <summary> 101 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'BigCount' function over the 102 /// specified collection. The result type of the expression is Edm.Int64. 103 /// </summary> 104 /// <param name="collection">An expression that specifies the collection over which the count value should be computed.</param> 105 /// <returns>A new DbFunctionExpression that produces the count value.</returns> 106 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 107 /// <exception cref="ArgumentException">No overload of the canonical 'BigCount' function accepts an argument with the result type of <paramref name="collection"/>.</exception> LongCount(this DbExpression collection)108 public static DbFunctionExpression LongCount(this DbExpression collection) 109 { 110 EntityUtil.CheckArgumentNull(collection, "collection"); 111 return InvokeCanonicalFunction("BigCount", collection); 112 } 113 114 /// <summary> 115 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Max' function over the 116 /// specified collection. The result type of the expression is the same as the element type of the collection. 117 /// </summary> 118 /// <param name="collection">An expression that specifies the collection from which the maximum value should be retrieved</param> 119 /// <returns>A new DbFunctionExpression that produces the maximum value.</returns> 120 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 121 /// <exception cref="ArgumentException">No overload of the canonical 'Max' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Max(this DbExpression collection)122 public static DbFunctionExpression Max(this DbExpression collection) 123 { 124 EntityUtil.CheckArgumentNull(collection, "collection"); 125 return InvokeCanonicalFunction("Max", collection); 126 } 127 128 /// <summary> 129 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Min' function over the 130 /// specified collection. The result type of the expression is the same as the element type of the collection. 131 /// </summary> 132 /// <param name="collection">An expression that specifies the collection from which the minimum value should be retrieved</param> 133 /// <returns>A new DbFunctionExpression that produces the minimum value.</returns> 134 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 135 /// <exception cref="ArgumentException">No overload of the canonical 'Min' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Min(this DbExpression collection)136 public static DbFunctionExpression Min(this DbExpression collection) 137 { 138 EntityUtil.CheckArgumentNull(collection, "collection"); 139 return InvokeCanonicalFunction("Min", collection); 140 } 141 142 /// <summary> 143 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Sum' function over the 144 /// specified collection. The result type of the expression is the same as the element type of the collection. 145 /// </summary> 146 /// <param name="collection">An expression that specifies the collection from which the sum should be computed</param> 147 /// <returns>A new DbFunctionExpression that produces the sum.</returns> 148 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 149 /// <exception cref="ArgumentException">No overload of the canonical 'Sum' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Sum(this DbExpression collection)150 public static DbFunctionExpression Sum(this DbExpression collection) 151 { 152 EntityUtil.CheckArgumentNull(collection, "collection"); 153 return InvokeCanonicalFunction("Sum", collection); 154 } 155 156 /// <summary> 157 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'StDev' function over the 158 /// non-null members of the specified collection. The result type of the expression is Edm.Double. 159 /// </summary> 160 /// <param name="collection">An expression that specifies the collection for which the standard deviation should be computed</param> 161 /// <returns>A new DbFunctionExpression that produces the standard deviation value over non-null members of the collection.</returns> 162 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 163 /// <exception cref="ArgumentException">No overload of the canonical 'StDev' function accepts an argument with the result type of <paramref name="collection"/>.</exception> 164 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "St")] StDev(this DbExpression collection)165 public static DbFunctionExpression StDev(this DbExpression collection) 166 { 167 EntityUtil.CheckArgumentNull(collection, "collection"); 168 return InvokeCanonicalFunction("StDev", collection); 169 } 170 171 /// <summary> 172 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'StDevP' function over the 173 /// population of the specified collection. The result type of the expression is Edm.Double. 174 /// </summary> 175 /// <param name="collection">An expression that specifies the collection for which the standard deviation should be computed</param> 176 /// <returns>A new DbFunctionExpression that produces the standard deviation value.</returns> 177 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 178 /// <exception cref="ArgumentException">No overload of the canonical 'StDevP' function accepts an argument with the result type of <paramref name="collection"/>.</exception> 179 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "St")] StDevP(this DbExpression collection)180 public static DbFunctionExpression StDevP(this DbExpression collection) 181 { 182 EntityUtil.CheckArgumentNull(collection, "collection"); 183 return InvokeCanonicalFunction("StDevP", collection); 184 } 185 186 /// <summary> 187 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Var' function over the 188 /// non-null members of the specified collection. The result type of the expression is Edm.Double. 189 /// </summary> 190 /// <param name="collection">An expression that specifies the collection for which the statistical variance should be computed</param> 191 /// <returns>A new DbFunctionExpression that produces the statistical variance value for the non-null members of the collection.</returns> 192 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 193 /// <exception cref="ArgumentException">No overload of the canonical 'Var' function accepts an argument with the result type of <paramref name="collection"/>.</exception> Var(this DbExpression collection)194 public static DbFunctionExpression Var(this DbExpression collection) 195 { 196 EntityUtil.CheckArgumentNull(collection, "collection"); 197 return InvokeCanonicalFunction("Var", collection); 198 } 199 200 /// <summary> 201 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'VarP' function over the 202 /// population of the specified collection. The result type of the expression Edm.Double. 203 /// </summary> 204 /// <param name="collection">An expression that specifies the collection for which the statistical variance should be computed</param> 205 /// <returns>A new DbFunctionExpression that produces the statistical variance value.</returns> 206 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> 207 /// <exception cref="ArgumentException">No overload of the canonical 'VarP' function accepts an argument with the result type of <paramref name="collection"/>.</exception> VarP(this DbExpression collection)208 public static DbFunctionExpression VarP(this DbExpression collection) 209 { 210 EntityUtil.CheckArgumentNull(collection, "collection"); 211 return InvokeCanonicalFunction("VarP", collection); 212 } 213 214 #endregion 215 216 #region String functions - Concat, Contains, EndsWith, IndexOf, Left, Length, LTrim, Replace, Reverse, Right, RTrim, StartsWith, Substring, ToUpper, ToLower, Trim 217 218 /// <summary> 219 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Concat' function with the 220 /// specified arguments, which must each have a string result type. The result type of the expression is 221 /// string. 222 /// </summary> 223 /// <param name="string1">An expression that specifies the string that should appear first in the concatenated result string.</param> 224 /// <param name="string2">An expression that specifies the string that should appear second in the concatenated result string.</param> 225 /// <returns>A new DbFunctionExpression that produces the concatenated string.</returns> 226 /// <exception cref="ArgumentNullException"><paramref name="string1"/> or <paramref name="string2"/>is null.</exception> 227 /// <exception cref="ArgumentException">No overload of the canonical 'Concat' function accepts arguments with the result types of <paramref name="string1"/> and <paramref name="string2"/>.</exception> Concat(this DbExpression string1, DbExpression string2)228 public static DbFunctionExpression Concat(this DbExpression string1, DbExpression string2) 229 { 230 EntityUtil.CheckArgumentNull(string1, "string1"); 231 EntityUtil.CheckArgumentNull(string2, "string2"); 232 return InvokeCanonicalFunction("Concat", string1, string2); 233 } 234 235 // 236 237 /// <summary> 238 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Contains' function with the 239 /// specified arguments, which must each have a string result type. The result type of the expression is 240 /// Boolean. 241 /// </summary> 242 /// <param name="searchedString">An expression that specifies the string to search for any occurence of <paramref name="searchedForString"/>.</param> 243 /// <param name="searchedForString">An expression that specifies the string to search for in <paramref name="searchedString"/>.</param> 244 /// <returns>A new DbFunctionExpression that returns a Boolean value indicating whether or not <paramref name="searchedForString"/> occurs within <paramref name="searchedString"/>.</returns> 245 /// <exception cref="ArgumentNullException"><paramref name="searchedString"/> or <paramref name="searchedForString"/>is null.</exception> 246 /// <exception cref="ArgumentException">No overload of the canonical 'Contains' function accepts arguments with the result types of <paramref name="searchedString"/> and <paramref name="searchedForString"/>.</exception> Contains(this DbExpression searchedString, DbExpression searchedForString)247 public static DbExpression Contains(this DbExpression searchedString, DbExpression searchedForString) 248 { 249 EntityUtil.CheckArgumentNull(searchedString, "searchedString"); 250 EntityUtil.CheckArgumentNull(searchedForString, "searchedForString"); 251 return InvokeCanonicalFunction("Contains", searchedString, searchedForString); 252 } 253 254 /// <summary> 255 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'EndsWith' function with the 256 /// specified arguments, which must each have a string result type. The result type of the expression is 257 /// Boolean. 258 /// </summary> 259 /// <param name="stringArgument">An expression that specifies the string to check for the specified <param name="suffix">.</param> 260 /// <param name="suffix">An expression that specifies the suffix for which <paramref name="stringArgument"/> should be checked.</param> 261 /// <returns>A new DbFunctionExpression that indicates whether <paramref name="stringArgument"/> ends with <paramref name="suffix"/>.</returns> 262 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> or <paramref name="suffix"/>is null.</exception> 263 /// <exception cref="ArgumentException">No overload of the canonical 'EndsWith' function accepts arguments with the result types of <paramref name="stringArgument"/> and <paramref name="suffix"/>.</exception> EndsWith(this DbExpression stringArgument, DbExpression suffix)264 public static DbFunctionExpression EndsWith(this DbExpression stringArgument, DbExpression suffix) 265 { 266 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 267 EntityUtil.CheckArgumentNull(suffix, "suffix"); 268 return InvokeCanonicalFunction("EndsWith", stringArgument, suffix); 269 } 270 271 /// <summary> 272 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'IndexOf' function with the 273 /// specified arguments, which must each have a string result type. The result type of the expression is 274 /// Edm.Int32. 275 /// </summary> 276 /// <remarks>The index returned by IndexOf is <b>1-based</b>.</remarks> 277 /// <param name="searchString">An expression that specifies the string to search for <paramref name="stringToFind"/>.</param> 278 /// <param name="stringToFind">An expression that specifies the string to locate within <paramref name="searchString"/> should be checked.</param> 279 /// <returns>A new DbFunctionExpression that returns the first index of <paramref name="stringToFind"/> in <paramref name="searchString"/>.</returns> 280 /// <exception cref="ArgumentNullException"><paramref name="searchString"/> or <paramref name="stringToFind"/>is null.</exception> 281 /// <exception cref="ArgumentException">No overload of the canonical 'IndexOf' function accepts arguments with the result types of <paramref name="searchString"/> and <paramref name="stringToFind"/>.</exception> IndexOf(this DbExpression searchString, DbExpression stringToFind)282 public static DbFunctionExpression IndexOf(this DbExpression searchString, DbExpression stringToFind) 283 { 284 EntityUtil.CheckArgumentNull(searchString, "searchString"); 285 EntityUtil.CheckArgumentNull(stringToFind, "stringToFind"); 286 return InvokeCanonicalFunction("IndexOf", stringToFind, searchString); 287 } 288 289 /// <summary> 290 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Left' function with the 291 /// specified arguments, which must have a string and integer numeric result type. The result type of the expression is 292 /// string. 293 /// </summary> 294 /// <param name="stringArgument">An expression that specifies the string from which to extract the leftmost substring.</param> 295 /// <param name="length">An expression that specifies the length of the leftmost substring to extract from <paramref name="stringArgument"/>.</param> 296 /// <returns>A new DbFunctionExpression that returns the the leftmost substring of length <paramref name="length"/> from <paramref name="stringArgument"/>.</returns> 297 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> or <paramref name="length"/>is null.</exception> 298 /// <exception cref="ArgumentException">No overload of the canonical 'Left' function accepts arguments with the result types of <paramref name="stringArgument"/>.</exception> Left(this DbExpression stringArgument, DbExpression length)299 public static DbFunctionExpression Left(this DbExpression stringArgument, DbExpression length) 300 { 301 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 302 EntityUtil.CheckArgumentNull(length, "length"); 303 return InvokeCanonicalFunction("Left", stringArgument, length); 304 } 305 306 /// <summary> 307 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Length' function with the 308 /// specified argument, which must have a string result type. The result type of the expression is 309 /// also string. 310 /// </summary> 311 /// <param name="stringArgument">An expression that specifies the string for which the length should be computed.</param> 312 /// <returns>A new DbFunctionExpression that returns the the length of <paramref name="stringArgument"/>.</returns> 313 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 314 /// <exception cref="ArgumentException">No overload of the canonical 'Length' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> Length(this DbExpression stringArgument)315 public static DbFunctionExpression Length(this DbExpression stringArgument) 316 { 317 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 318 return InvokeCanonicalFunction("Length", stringArgument); 319 } 320 321 /// <summary> 322 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Replace' function with the 323 /// specified arguments, which must each have a string result type. The result type of the expression is 324 /// also string. 325 /// </summary> 326 /// <param name="stringArgument">An expression that specifies the string in which to perform the replacement operation</param> 327 /// <param name="toReplace">An expression that specifies the string to replace</param> 328 /// <param name="replacement">An expression that specifies the replacement string</param> 329 /// <returns>A new DbFunctionExpression than returns a new string based on <paramref name="stringArgument"/> where every occurence of <paramref name="toReplace"/> is replaced by <paramref name="replacement"/>.</returns> 330 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/>, <paramref name="toReplace"/> or <paramref name="replacement"/> is null.</exception> 331 /// <exception cref="ArgumentException">No overload of the canonical 'Length' function accepts arguments with the result types of <paramref name="stringArgument"/>, <paramref name="toReplace"/> and <paramref name="replacement"/>.</exception> Replace(this DbExpression stringArgument, DbExpression toReplace, DbExpression replacement)332 public static DbFunctionExpression Replace(this DbExpression stringArgument, DbExpression toReplace, DbExpression replacement) 333 { 334 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 335 EntityUtil.CheckArgumentNull(toReplace, "toReplace"); 336 EntityUtil.CheckArgumentNull(replacement, "replacement"); 337 return InvokeCanonicalFunction("Replace", stringArgument, toReplace, replacement); 338 } 339 340 /// <summary> 341 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Reverse' function with the 342 /// specified argument, which must have a string result type. The result type of the expression is 343 /// also string. 344 /// </summary> 345 /// <param name="stringArgument">An expression that specifies the string to reverse.</param> 346 /// <returns>A new DbFunctionExpression that produces the reversed value of <paramref name="stringArgument"/>.</returns> 347 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 348 /// <exception cref="ArgumentException">No overload of the canonical 'Reverse' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> Reverse(this DbExpression stringArgument)349 public static DbFunctionExpression Reverse(this DbExpression stringArgument) 350 { 351 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 352 return InvokeCanonicalFunction("Reverse", stringArgument); 353 } 354 355 /// <summary> 356 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Right' function with the 357 /// specified arguments, which must have a string and integer numeric result type. The result type of the expression is 358 /// string. 359 /// </summary> 360 /// <param name="stringArgument">An expression that specifies the string from which to extract the rightmost substring.</param> 361 /// <param name="length">An expression that specifies the length of the rightmost substring to extract from <paramref name="stringArgument"/>.</param> 362 /// <returns>A new DbFunctionExpression that returns the the rightmost substring of length <paramref name="length"/> from <paramref name="stringArgument"/>.</returns> 363 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> or <paramref name="length"/>is null.</exception> 364 /// <exception cref="ArgumentException">No overload of the canonical 'Right' function accepts arguments with the result types of <paramref name="stringArgument"/>.</exception> Right(this DbExpression stringArgument, DbExpression length)365 public static DbFunctionExpression Right(this DbExpression stringArgument, DbExpression length) 366 { 367 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 368 EntityUtil.CheckArgumentNull(length, "length"); 369 return InvokeCanonicalFunction("Right", stringArgument, length); 370 } 371 372 /// <summary> 373 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'StartsWith' function with the 374 /// specified arguments, which must each have a string result type. The result type of the expression is 375 /// Boolean. 376 /// </summary> 377 /// <param name="stringArgument">An expression that specifies the string to check for the specified <param name="prefix">.</param> 378 /// <param name="suffix">An expression that specifies the prefix for which <paramref name="stringArgument"/> should be checked.</param> 379 /// <returns>A new DbFunctionExpression that indicates whether <paramref name="stringArgument"/> starts with <paramref name="prefix"/>.</returns> 380 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> or <paramref name="prefix"/>is null.</exception> 381 /// <exception cref="ArgumentException">No overload of the canonical 'StartsWith' function accepts arguments with the result types of <paramref name="stringArgument"/> and <paramref name="prefix"/>.</exception> StartsWith(this DbExpression stringArgument, DbExpression prefix)382 public static DbFunctionExpression StartsWith(this DbExpression stringArgument, DbExpression prefix) 383 { 384 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 385 EntityUtil.CheckArgumentNull(prefix, "prefix"); 386 return InvokeCanonicalFunction("StartsWith", stringArgument, prefix); 387 } 388 389 // 390 391 /// <summary> 392 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Substring' function with the 393 /// specified arguments, which must have a string and integer numeric result types. The result type of the 394 /// expression is string. 395 /// </summary> 396 /// <remarks>Substring requires that the index specified by <paramref name="start"/> be <b>1-based</b>.</remarks> 397 /// <param name="stringArgument">An expression that specifies the string from which to extract the substring.</param> 398 /// <param name="start">An expression that specifies the starting index from which the substring should be taken.</param> 399 /// <param name="length">An expression that specifies the length of the substring.</param> 400 /// <returns>A new DbFunctionExpression that returns the substring of length <paramref name="length"/> from <paramref name="stringArgument"/> starting at <paramref name="start"/>.</returns> 401 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/>, <paramref name="start"/> or <paramref name="length"/>is null.</exception> 402 /// <exception cref="ArgumentException">No overload of the canonical 'Substring' function accepts arguments with the result types of <paramref name="stringArgument"/>, <paramref name="start"/> and <paramref name="length"/>.</exception> Substring(this DbExpression stringArgument, DbExpression start, DbExpression length)403 public static DbFunctionExpression Substring(this DbExpression stringArgument, DbExpression start, DbExpression length) 404 { 405 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 406 EntityUtil.CheckArgumentNull(start, "start"); 407 EntityUtil.CheckArgumentNull(length, "length"); 408 return InvokeCanonicalFunction("Substring", stringArgument, start, length); 409 } 410 411 /// <summary> 412 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'ToLower' function with the 413 /// specified argument, which must have a string result type. The result type of the expression is 414 /// also string. 415 /// </summary> 416 /// <param name="stringArgument">An expression that specifies the string that should be converted to lower case.</param> 417 /// <returns>A new DbFunctionExpression that returns value of <paramref name="stringArgument"/> converted to lower case.</returns> 418 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 419 /// <exception cref="ArgumentException">No overload of the canonical 'ToLower' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> ToLower(this DbExpression stringArgument)420 public static DbFunctionExpression ToLower(this DbExpression stringArgument) 421 { 422 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 423 return InvokeCanonicalFunction("ToLower", stringArgument); 424 } 425 426 /// <summary> 427 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'ToUpper' function with the 428 /// specified argument, which must have a string result type. The result type of the expression is 429 /// also string. 430 /// </summary> 431 /// <param name="stringArgument">An expression that specifies the string that should be converted to upper case.</param> 432 /// <returns>A new DbFunctionExpression that returns value of <paramref name="stringArgument"/> converted to upper case.</returns> 433 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 434 /// <exception cref="ArgumentException">No overload of the canonical 'ToUpper' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> ToUpper(this DbExpression stringArgument)435 public static DbFunctionExpression ToUpper(this DbExpression stringArgument) 436 { 437 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 438 return InvokeCanonicalFunction("ToUpper", stringArgument); 439 } 440 441 /// <summary> 442 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Trim' function with the 443 /// specified argument, which must have a string result type. The result type of the expression is 444 /// also string. 445 /// </summary> 446 /// <param name="stringArgument">An expression that specifies the string from which leading and trailing space should be removed.</param> 447 /// <returns>A new DbFunctionExpression that returns value of <paramref name="stringArgument"/> with leading and trailing space removed.</returns> 448 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 449 /// <exception cref="ArgumentException">No overload of the canonical 'Trim' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> Trim(this DbExpression stringArgument)450 public static DbFunctionExpression Trim(this DbExpression stringArgument) 451 { 452 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 453 return InvokeCanonicalFunction("Trim", stringArgument); 454 } 455 456 /// <summary> 457 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'RTrim' function with the 458 /// specified argument, which must have a string result type. The result type of the expression is 459 /// also string. 460 /// </summary> 461 /// <param name="stringArgument">An expression that specifies the string from which trailing space should be removed.</param> 462 /// <returns>A new DbFunctionExpression that returns value of <paramref name="stringArgument"/> with trailing space removed.</returns> 463 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 464 /// <exception cref="ArgumentException">No overload of the canonical 'RTrim' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> TrimEnd(this DbExpression stringArgument)465 public static DbFunctionExpression TrimEnd(this DbExpression stringArgument) 466 { 467 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 468 return InvokeCanonicalFunction("RTrim", stringArgument); 469 } 470 471 /// <summary> 472 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'LTrim' function with the 473 /// specified argument, which must have a string result type. The result type of the expression is 474 /// also string. 475 /// </summary> 476 /// <param name="stringArgument">An expression that specifies the string from which leading space should be removed.</param> 477 /// <returns>A new DbFunctionExpression that returns value of <paramref name="stringArgument"/> with leading space removed.</returns> 478 /// <exception cref="ArgumentNullException"><paramref name="stringArgument"/> is null.</exception> 479 /// <exception cref="ArgumentException">No overload of the canonical 'LTrim' function accepts an argument with the result type of <paramref name="stringArgument"/>.</exception> TrimStart(this DbExpression stringArgument)480 public static DbFunctionExpression TrimStart(this DbExpression stringArgument) 481 { 482 EntityUtil.CheckArgumentNull(stringArgument, "stringArgument"); 483 return InvokeCanonicalFunction("LTrim", stringArgument); 484 } 485 486 #endregion 487 488 #region Date/Time member access methods - Year, Month, Day, DayOfYear, Hour, Minute, Second, Millisecond, GetTotalOffsetMinutes 489 490 /// <summary> 491 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Year' function with the 492 /// specified argument, which must have a DateTime or DateTimeOffset result type. The result type of 493 /// the expression is Edm.Int32. 494 /// </summary> 495 /// <param name="dateValue">An expression that specifies the value from which the year should be retrieved.</param> 496 /// <returns>A new DbFunctionExpression that returns the integer year value from <paramref name="dateValue"/>.</returns> 497 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> is null.</exception> 498 /// <exception cref="ArgumentException">No overload of the canonical 'Year' function accepts an argument with the result type of <paramref name="dateValue"/>.</exception> Year(this DbExpression dateValue)499 public static DbFunctionExpression Year(this DbExpression dateValue) 500 { 501 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 502 return InvokeCanonicalFunction("Year", dateValue); 503 } 504 505 /// <summary> 506 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Month' function with the 507 /// specified argument, which must have a DateTime or DateTimeOffset result type. The result type of 508 /// the expression is Edm.Int32. 509 /// </summary> 510 /// <param name="dateValue">An expression that specifies the value from which the month should be retrieved.</param> 511 /// <returns>A new DbFunctionExpression that returns the integer month value from <paramref name="dateValue"/>.</returns> 512 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> is null.</exception> 513 /// <exception cref="ArgumentException">No overload of the canonical 'Month' function accepts an argument with the result type of <paramref name="dateValue"/>.</exception> Month(this DbExpression dateValue)514 public static DbFunctionExpression Month(this DbExpression dateValue) 515 { 516 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 517 return InvokeCanonicalFunction("Month", dateValue); 518 } 519 520 /// <summary> 521 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Day' function with the 522 /// specified argument, which must have a DateTime or DateTimeOffset result type. The result type of 523 /// the expression is Edm.Int32. 524 /// </summary> 525 /// <param name="dateValue">An expression that specifies the value from which the day should be retrieved.</param> 526 /// <returns>A new DbFunctionExpression that returns the integer day value from <paramref name="dateValue"/>.</returns> 527 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> is null.</exception> 528 /// <exception cref="ArgumentException">No overload of the canonical 'Day' function accepts an argument with the result type of <paramref name="dateValue"/>.</exception> Day(this DbExpression dateValue)529 public static DbFunctionExpression Day(this DbExpression dateValue) 530 { 531 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 532 return InvokeCanonicalFunction("Day", dateValue); 533 } 534 535 /// <summary> 536 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DayOfYear' function with the 537 /// specified argument, which must have a DateTime or DateTimeOffset result type. The result type of 538 /// the expression is Edm.Int32. 539 /// </summary> 540 /// <param name="dateValue">An expression that specifies the value from which the day within the year should be retrieved.</param> 541 /// <returns>A new DbFunctionExpression that returns the integer day of year value from <paramref name="dateValue"/>.</returns> 542 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> is null.</exception> 543 /// <exception cref="ArgumentException">No overload of the canonical 'DayOfYear' function accepts an argument with the result type of <paramref name="dateValue"/>.</exception> DayOfYear(this DbExpression dateValue)544 public static DbFunctionExpression DayOfYear(this DbExpression dateValue) 545 { 546 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 547 return InvokeCanonicalFunction("DayOfYear", dateValue); 548 } 549 550 /// <summary> 551 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Hour' function with the 552 /// specified argument, which must have a DateTime, DateTimeOffset or Time result type. The result type of 553 /// the expression is Edm.Int32. 554 /// </summary> 555 /// <param name="timeValue">An expression that specifies the value from which the hour should be retrieved.</param> 556 /// <returns>A new DbFunctionExpression that returns the integer hour value from <paramref name="timeValue"/>.</returns> 557 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> is null.</exception> 558 /// <exception cref="ArgumentException">No overload of the canonical 'Hour' function accepts an argument with the result type of <paramref name="timeValue"/>.</exception> Hour(this DbExpression timeValue)559 public static DbFunctionExpression Hour(this DbExpression timeValue) 560 { 561 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 562 return InvokeCanonicalFunction("Hour", timeValue); 563 } 564 565 /// <summary> 566 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Minute' function with the 567 /// specified argument, which must have a DateTime, DateTimeOffset or Time result type. The result type of 568 /// the expression is Edm.Int32. 569 /// </summary> 570 /// <param name="timeValue">An expression that specifies the value from which the minute should be retrieved.</param> 571 /// <returns>A new DbFunctionExpression that returns the integer minute value from <paramref name="timeValue"/>.</returns> 572 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> is null.</exception> 573 /// <exception cref="ArgumentException">No overload of the canonical 'Minute' function accepts an argument with the result type of <paramref name="timeValue"/>.</exception> Minute(this DbExpression timeValue)574 public static DbFunctionExpression Minute(this DbExpression timeValue) 575 { 576 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 577 return InvokeCanonicalFunction("Minute", timeValue); 578 } 579 580 /// <summary> 581 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Second' function with the 582 /// specified argument, which must have a DateTime, DateTimeOffset or Time result type. The result type of 583 /// the expression is Edm.Int32. 584 /// </summary> 585 /// <param name="timeValue">An expression that specifies the value from which the second should be retrieved.</param> 586 /// <returns>A new DbFunctionExpression that returns the integer second value from <paramref name="timeValue"/>.</returns> 587 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> is null.</exception> 588 /// <exception cref="ArgumentException">No overload of the canonical 'Second' function accepts an argument with the result type of <paramref name="timeValue"/>.</exception> Second(this DbExpression timeValue)589 public static DbFunctionExpression Second(this DbExpression timeValue) 590 { 591 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 592 return InvokeCanonicalFunction("Second", timeValue); 593 } 594 595 /// <summary> 596 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Millisecond' function with the 597 /// specified argument, which must have a DateTime, DateTimeOffset or Time result type. The result type of 598 /// the expression is Edm.Int32. 599 /// </summary> 600 /// <param name="timeValue">An expression that specifies the value from which the millisecond should be retrieved.</param> 601 /// <returns>A new DbFunctionExpression that returns the integer millisecond value from <paramref name="timeValue"/>.</returns> 602 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> is null.</exception> 603 /// <exception cref="ArgumentException">No overload of the canonical 'Millisecond' function accepts an argument with the result type of <paramref name="timeValue"/>.</exception> Millisecond(this DbExpression timeValue)604 public static DbFunctionExpression Millisecond(this DbExpression timeValue) 605 { 606 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 607 return InvokeCanonicalFunction("Millisecond", timeValue); 608 } 609 610 /// <summary> 611 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'GetTotalOffsetMinutes' function with the 612 /// specified argument, which must have a DateTimeOffset result type. The result type of the expression is Edm.Int32. 613 /// </summary> 614 /// <param name="dateTimeOffsetArgument">An expression that specifies the DateTimeOffset value from which the minute offset from GMT should be retrieved.</param> 615 /// <returns>A new DbFunctionExpression that returns the number of minutes <paramref name="dateTimeOffsetArgument"/> is offset from GMT.</returns> 616 /// <exception cref="ArgumentNullException"><paramref name="dateTimeOffsetArgument"/> is null.</exception> 617 /// <exception cref="ArgumentException">No overload of the canonical 'GetTotalOffsetMinutes' function accepts an argument with the result type of <paramref name="dateTimeOffsetArgument"/>.</exception> GetTotalOffsetMinutes(this DbExpression dateTimeOffsetArgument)618 public static DbFunctionExpression GetTotalOffsetMinutes(this DbExpression dateTimeOffsetArgument) 619 { 620 EntityUtil.CheckArgumentNull(dateTimeOffsetArgument, "dateTimeOffsetArgument"); 621 return InvokeCanonicalFunction("GetTotalOffsetMinutes", dateTimeOffsetArgument); 622 } 623 624 #endregion 625 626 #region Date/Time creation methods - CurrentDateTime, CurrentDateTimeOffset, CurrentUtcDateTime, CreateDateTime, CreateDateTimeOffset, CreateTime, TruncateTime 627 628 /// <summary> 629 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CurrentDateTime' function. 630 /// </summary> 631 /// <returns>A new DbFunctionExpression that returns the current date and time as an Edm.DateTime instance.</returns> CurrentDateTime()632 public static DbFunctionExpression CurrentDateTime() 633 { 634 return InvokeCanonicalFunction("CurrentDateTime"); 635 } 636 637 /// <summary> 638 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CurrentDateTimeOffset' function. 639 /// </summary> 640 /// <returns>A new DbFunctionExpression that returns the current date and time as an Edm.DateTimeOffset instance.</returns> CurrentDateTimeOffset()641 public static DbFunctionExpression CurrentDateTimeOffset() 642 { 643 return InvokeCanonicalFunction("CurrentDateTimeOffset"); 644 } 645 646 /// <summary> 647 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CurrentUtcDateTime' function. 648 /// </summary> 649 /// <returns>A new DbFunctionExpression that returns the current UTC date and time as an Edm.DateTime instance.</returns> CurrentUtcDateTime()650 public static DbFunctionExpression CurrentUtcDateTime() 651 { 652 return InvokeCanonicalFunction("CurrentUtcDateTime"); 653 } 654 655 /// <summary> 656 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'TruncateTime' function with the 657 /// specified argument, which must have a DateTime or DateTimeOffset result type. The result type of the 658 /// expression is the same as the result type of <paramref name="dateValue"/>. 659 /// </summary> 660 /// <param name="dateValue">An expression that specifies the value for which the time portion should be truncated.</param> 661 /// <returns>A new DbFunctionExpression that returns the value of <paramref name="dateValue"/> with time set to zero.</returns> 662 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> is null.</exception> 663 /// <exception cref="ArgumentException">No overload of the canonical 'TruncateTime' function accepts an argument with the result type of <paramref name="dateValue"/>.</exception> TruncateTime(this DbExpression dateValue)664 public static DbFunctionExpression TruncateTime(this DbExpression dateValue) 665 { 666 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 667 return InvokeCanonicalFunction("TruncateTime", dateValue); 668 } 669 670 /// <summary> 671 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CreateDateTime' function with the 672 /// specified arguments. <paramref name="second"/> must have a result type of Edm.Double, while all other arguments 673 /// must have a result type of Edm.Int32. The result type of the expression is Edm.DateTime. 674 /// </summary> 675 /// <param name="year">An expression that provides the year value for the new DateTime instance.</param> 676 /// <param name="month">An expression that provides the month value for the new DateTime instance.</param> 677 /// <param name="day">An expression that provides the day value for the new DateTime instance.</param> 678 /// <param name="hour">An expression that provides the hour value for the new DateTime instance.</param> 679 /// <param name="minute">An expression that provides the minute value for the new DateTime instance.</param> 680 /// <param name="second">An expression that provides the second value for the new DateTime instance.</param> 681 /// <returns>A new DbFunctionExpression that returns a new DateTime based on the specified values.</returns> 682 /// <exception cref="ArgumentNullException"><paramref name="year"/>, <paramref name="month"/>, <paramref name="day"/>, <paramref name="hour"/>, <paramref name="minute"/>, or <paramref name="second"/> is null.</exception> 683 /// <exception cref="ArgumentException">No overload of the canonical 'CreateDateTime' function accepts arguments with the result types of <paramref name="year"/>, <paramref name="month"/>, <paramref name="day"/>, <paramref name="hour"/>, <paramref name="minute"/>, and <paramref name="second"/>.</exception> CreateDateTime(DbExpression year, DbExpression month, DbExpression day, DbExpression hour, DbExpression minute, DbExpression second)684 public static DbFunctionExpression CreateDateTime(DbExpression year, DbExpression month, DbExpression day, DbExpression hour, DbExpression minute, DbExpression second) 685 { 686 EntityUtil.CheckArgumentNull(year, "year"); 687 EntityUtil.CheckArgumentNull(month, "month"); 688 EntityUtil.CheckArgumentNull(day, "day"); 689 EntityUtil.CheckArgumentNull(hour, "hour"); 690 EntityUtil.CheckArgumentNull(minute, "minute"); 691 EntityUtil.CheckArgumentNull(second, "second"); 692 return InvokeCanonicalFunction("CreateDateTime", year, month, day, hour, minute, second); 693 } 694 695 /// <summary> 696 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CreateDateTimeOffset' function with the 697 /// specified arguments. <paramref name="second"/> must have a result type of Edm.Double, while all other arguments 698 /// must have a result type of Edm.Int32. The result type of the expression is Edm.DateTimeOffset. 699 /// </summary> 700 /// <param name="year">An expression that provides the year value for the new DateTimeOffset instance.</param> 701 /// <param name="month">An expression that provides the month value for the new DateTimeOffset instance.</param> 702 /// <param name="day">An expression that provides the day value for the new DateTimeOffset instance.</param> 703 /// <param name="hour">An expression that provides the hour value for the new DateTimeOffset instance.</param> 704 /// <param name="minute">An expression that provides the minute value for the new DateTimeOffset instance.</param> 705 /// <param name="second">An expression that provides the second value for the new DateTimeOffset instance.</param> 706 /// <param name="timeZoneOffset">An expression that provides the number of minutes in the time zone offset value for the new DateTimeOffset instance.</param> 707 /// <returns>A new DbFunctionExpression that returns a new DateTimeOffset based on the specified values.</returns> 708 /// <exception cref="ArgumentNullException"><paramref name="year"/>, <paramref name="month"/>, <paramref name="day"/>, <paramref name="hour"/>, <paramref name="minute"/>, <paramref name="second"/> or <paramref name="timeZoneOffset"/> is null.</exception> 709 /// <exception cref="ArgumentException">No overload of the canonical 'CreateDateTimeOffset' function accepts arguments with the result types of <paramref name="year"/>, <paramref name="month"/>, <paramref name="day"/>, <paramref name="hour"/>, <paramref name="minute"/>, <paramref name="second"/> and <paramref name="timeZoneOffset"/>.</exception> CreateDateTimeOffset(DbExpression year, DbExpression month, DbExpression day, DbExpression hour, DbExpression minute, DbExpression second, DbExpression timeZoneOffset)710 public static DbFunctionExpression CreateDateTimeOffset(DbExpression year, DbExpression month, DbExpression day, DbExpression hour, DbExpression minute, DbExpression second, DbExpression timeZoneOffset) 711 { 712 EntityUtil.CheckArgumentNull(year, "year"); 713 EntityUtil.CheckArgumentNull(month, "month"); 714 EntityUtil.CheckArgumentNull(day, "day"); 715 EntityUtil.CheckArgumentNull(hour, "hour"); 716 EntityUtil.CheckArgumentNull(minute, "minute"); 717 EntityUtil.CheckArgumentNull(second, "second"); 718 EntityUtil.CheckArgumentNull(timeZoneOffset, "timeZoneOffset"); 719 return InvokeCanonicalFunction("CreateDateTimeOffset", year, month, day, hour, minute, second, timeZoneOffset); 720 } 721 722 /// <summary> 723 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'CreateTime' function with the 724 /// specified arguments. <paramref name="second"/> must have a result type of Edm.Double, while all other arguments 725 /// must have a result type of Edm.Int32. The result type of the expression is Edm.Time. 726 /// </summary> 727 /// <param name="hour">An expression that provides the hour value for the new DateTime instance.</param> 728 /// <param name="minute">An expression that provides the minute value for the new DateTime instance.</param> 729 /// <param name="second">An expression that provides the second value for the new DateTime instance.</param> 730 /// <returns>A new DbFunctionExpression that returns a new Time based on the specified values.</returns> 731 /// <exception cref="ArgumentNullException"><paramref name="hour"/>, <paramref name="minute"/>, or <paramref name="second"/> is null.</exception> 732 /// <exception cref="ArgumentException">No overload of the canonical 'CreateTime' function accepts arguments with the result types of <paramref name="hour"/>, <paramref name="minute"/>, and <paramref name="second"/>.</exception> CreateTime(DbExpression hour, DbExpression minute, DbExpression second)733 public static DbFunctionExpression CreateTime(DbExpression hour, DbExpression minute, DbExpression second) 734 { 735 EntityUtil.CheckArgumentNull(hour, "hour"); 736 EntityUtil.CheckArgumentNull(minute, "minute"); 737 EntityUtil.CheckArgumentNull(second, "second"); 738 return InvokeCanonicalFunction("CreateTime", hour, minute, second); 739 } 740 741 #endregion 742 743 #region Date/Time addition - AddYears, AddMonths, AddDays, AddHours, AddMinutes, AddSeconds, AddMilliseconds, AddMicroseconds, AddNanoseconds 744 745 /// <summary> 746 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddYears' function with the 747 /// specified arguments, which must have DateTime or DateTimeOffset and integer result types. The result 748 /// type of the expression is the same as the result type of <paramref name="dateValue"/>. 749 /// </summary> 750 /// <param name="dateValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 751 /// <param name="addValue">An expression that specifies the number of years to add to <paramref name="dateValue"/>.</param> 752 /// <returns>A new DbFunctionExpression that adds the number of years specified by <paramref name="addValue"/> to the value specified by <paramref name="dateValue"/>.</returns> 753 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> or <paramref name="addValue"/> is null.</exception> 754 /// <exception cref="ArgumentException">No overload of the canonical 'AddYears' function accepts arguments with the result types of <paramref name="dateValue"/> and <paramref name="addValue"/>.</exception> AddYears(this DbExpression dateValue, DbExpression addValue)755 public static DbFunctionExpression AddYears(this DbExpression dateValue, DbExpression addValue) 756 { 757 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 758 EntityUtil.CheckArgumentNull(addValue, "addValue"); 759 return InvokeCanonicalFunction("AddYears", dateValue, addValue); 760 } 761 762 /// <summary> 763 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddMonths' function with the 764 /// specified arguments, which must have DateTime or DateTimeOffset and integer result types. The result 765 /// type of the expression is the same as the result type of <paramref name="dateValue"/>. 766 /// </summary> 767 /// <param name="dateValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 768 /// <param name="addValue">An expression that specifies the number of months to add to <paramref name="dateValue"/>.</param> 769 /// <returns>A new DbFunctionExpression that adds the number of months specified by <paramref name="addValue"/> to the value specified by <paramref name="dateValue"/>.</returns> 770 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> or <paramref name="addValue"/> is null.</exception> 771 /// <exception cref="ArgumentException">No overload of the canonical 'AddMonths' function accepts arguments with the result types of <paramref name="dateValue"/> and <paramref name="addValue"/>.</exception> AddMonths(this DbExpression dateValue, DbExpression addValue)772 public static DbFunctionExpression AddMonths(this DbExpression dateValue, DbExpression addValue) 773 { 774 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 775 EntityUtil.CheckArgumentNull(addValue, "addValue"); 776 return InvokeCanonicalFunction("AddMonths", dateValue, addValue); 777 } 778 779 /// <summary> 780 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddDays' function with the 781 /// specified arguments, which must have DateTime or DateTimeOffset and integer result types. The result 782 /// type of the expression is the same as the result type of <paramref name="dateValue"/>. 783 /// </summary> 784 /// <param name="dateValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 785 /// <param name="addValue">An expression that specifies the number of days to add to <paramref name="dateValue"/>.</param> 786 /// <returns>A new DbFunctionExpression that adds the number of days specified by <paramref name="addValue"/> to the value specified by <paramref name="dateValue"/>.</returns> 787 /// <exception cref="ArgumentNullException"><paramref name="dateValue"/> or <paramref name="addValue"/> is null.</exception> 788 /// <exception cref="ArgumentException">No overload of the canonical 'AddDays' function accepts arguments with the result types of <paramref name="dateValue"/> and <paramref name="addValue"/>.</exception> AddDays(this DbExpression dateValue, DbExpression addValue)789 public static DbFunctionExpression AddDays(this DbExpression dateValue, DbExpression addValue) 790 { 791 EntityUtil.CheckArgumentNull(dateValue, "dateValue"); 792 EntityUtil.CheckArgumentNull(addValue, "addValue"); 793 return InvokeCanonicalFunction("AddDays", dateValue, addValue); 794 } 795 796 /// <summary> 797 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddHours' function with the 798 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 799 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 800 /// </summary> 801 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 802 /// <param name="addValue">An expression that specifies the number of hours to add to <paramref name="timeValue"/>.</param> 803 /// <returns>A new DbFunctionExpression that adds the number of hours specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 804 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 805 /// <exception cref="ArgumentException">No overload of the canonical 'AddHours' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddHours(this DbExpression timeValue, DbExpression addValue)806 public static DbFunctionExpression AddHours(this DbExpression timeValue, DbExpression addValue) 807 { 808 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 809 EntityUtil.CheckArgumentNull(addValue, "addValue"); 810 return InvokeCanonicalFunction("AddHours", timeValue, addValue); 811 } 812 813 /// <summary> 814 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddMinutes' function with the 815 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 816 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 817 /// </summary> 818 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 819 /// <param name="addValue">An expression that specifies the number of minutes to add to <paramref name="timeValue"/>.</param> 820 /// <returns>A new DbFunctionExpression that adds the number of minutes specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 821 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 822 /// <exception cref="ArgumentException">No overload of the canonical 'AddMinutes' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddMinutes(this DbExpression timeValue, DbExpression addValue)823 public static DbFunctionExpression AddMinutes(this DbExpression timeValue, DbExpression addValue) 824 { 825 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 826 EntityUtil.CheckArgumentNull(addValue, "addValue"); 827 return InvokeCanonicalFunction("AddMinutes", timeValue, addValue); 828 } 829 830 /// <summary> 831 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddSeconds' function with the 832 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 833 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 834 /// </summary> 835 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 836 /// <param name="addValue">An expression that specifies the number of seconds to add to <paramref name="timeValue"/>.</param> 837 /// <returns>A new DbFunctionExpression that adds the number of seconds specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 838 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 839 /// <exception cref="ArgumentException">No overload of the canonical 'AddSeconds' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddSeconds(this DbExpression timeValue, DbExpression addValue)840 public static DbFunctionExpression AddSeconds(this DbExpression timeValue, DbExpression addValue) 841 { 842 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 843 EntityUtil.CheckArgumentNull(addValue, "addValue"); 844 return InvokeCanonicalFunction("AddSeconds", timeValue, addValue); 845 } 846 847 /// <summary> 848 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddMilliseconds' function with the 849 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 850 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 851 /// </summary> 852 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 853 /// <param name="addValue">An expression that specifies the number of milliseconds to add to <paramref name="timeValue"/>.</param> 854 /// <returns>A new DbFunctionExpression that adds the number of milliseconds specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 855 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 856 /// <exception cref="ArgumentException">No overload of the canonical 'AddMilliseconds' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddMilliseconds(this DbExpression timeValue, DbExpression addValue)857 public static DbFunctionExpression AddMilliseconds(this DbExpression timeValue, DbExpression addValue) 858 { 859 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 860 EntityUtil.CheckArgumentNull(addValue, "addValue"); 861 return InvokeCanonicalFunction("AddMilliseconds", timeValue, addValue); 862 } 863 864 /// <summary> 865 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddMicroseconds' function with the 866 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 867 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 868 /// </summary> 869 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 870 /// <param name="addValue">An expression that specifies the number of microseconds to add to <paramref name="timeValue"/>.</param> 871 /// <returns>A new DbFunctionExpression that adds the number of microseconds specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 872 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 873 /// <exception cref="ArgumentException">No overload of the canonical 'AddMicroseconds' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddMicroseconds(this DbExpression timeValue, DbExpression addValue)874 public static DbFunctionExpression AddMicroseconds(this DbExpression timeValue, DbExpression addValue) 875 { 876 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 877 EntityUtil.CheckArgumentNull(addValue, "addValue"); 878 return InvokeCanonicalFunction("AddMicroseconds", timeValue, addValue); 879 } 880 881 /// <summary> 882 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'AddNanoseconds' function with the 883 /// specified arguments, which must have DateTime, DateTimeOffset or Time, and integer result types. The result 884 /// type of the expression is the same as the result type of <paramref name="timeValue"/>. 885 /// </summary> 886 /// <param name="timeValue">An expression that specifies the value to which <paramref name="addValue"/>should be added.</param> 887 /// <param name="addValue">An expression that specifies the number of nanoseconds to add to <paramref name="timeValue"/>.</param> 888 /// <returns>A new DbFunctionExpression that adds the number of nanoseconds specified by <paramref name="addValue"/> to the value specified by <paramref name="timeValue"/>.</returns> 889 /// <exception cref="ArgumentNullException"><paramref name="timeValue"/> or <paramref name="addValue"/> is null.</exception> 890 /// <exception cref="ArgumentException">No overload of the canonical 'AddNanoseconds' function accepts arguments with the result types of <paramref name="timeValue"/> and <paramref name="addValue"/>.</exception> AddNanoseconds(this DbExpression timeValue, DbExpression addValue)891 public static DbFunctionExpression AddNanoseconds(this DbExpression timeValue, DbExpression addValue) 892 { 893 EntityUtil.CheckArgumentNull(timeValue, "timeValue"); 894 EntityUtil.CheckArgumentNull(addValue, "addValue"); 895 return InvokeCanonicalFunction("AddNanoseconds", timeValue, addValue); 896 } 897 898 #endregion 899 900 #region Date/Time difference - DiffYears, DiffMonths, DiffDays, DiffHours, DiffMinutes, DiffSeconds, DiffMilliseconds, DiffMicroseconds, DiffNanoseconds 901 902 /// <summary> 903 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffYears' function with the 904 /// specified arguments, which must each have a DateTime or DateTimeOffset result type. The result type of 905 /// <paramref name="dateValue1"/> must match the result type of <paramref name="dateValue2"/>. 906 /// The result type of the expression is Edm.Int32. 907 /// </summary> 908 /// <param name="dateValue1">An expression that specifies the first DateTime or DateTimeOffset value.</param> 909 /// <param name="dateValue2">An expression that specifies the DateTime or DateTimeOffset for which the year difference from <paramref name="dateValue1"/> should be calculated.</param> 910 /// <returns>A new DbFunctionExpression that returns the year difference between <param name="dateValue1"> and <param name="dateValue2">.</returns> 911 /// <exception cref="ArgumentNullException"><paramref name="dateValue1"/> or <paramref name="dateValue2"/> is null.</exception> 912 /// <exception cref="ArgumentException">No overload of the canonical 'DiffYears' function accepts arguments with the result types of <paramref name="dateValue1"/> and <paramref name="dateValue2"/>.</exception> DiffYears(this DbExpression dateValue1, DbExpression dateValue2)913 public static DbFunctionExpression DiffYears(this DbExpression dateValue1, DbExpression dateValue2) 914 { 915 EntityUtil.CheckArgumentNull(dateValue1, "dateValue1"); 916 EntityUtil.CheckArgumentNull(dateValue2, "dateValue2"); 917 return InvokeCanonicalFunction("DiffYears", dateValue1, dateValue2); 918 } 919 920 /// <summary> 921 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffMonths' function with the 922 /// specified arguments, which must each have a DateTime or DateTimeOffset result type. The result type of 923 /// <paramref name="dateValue1"/> must match the result type of <paramref name="dateValue2"/>. 924 /// The result type of the expression is Edm.Int32. 925 /// </summary> 926 /// <param name="dateValue1">An expression that specifies the first DateTime or DateTimeOffset value.</param> 927 /// <param name="dateValue2">An expression that specifies the DateTime or DateTimeOffset for which the month difference from <paramref name="dateValue1"/> should be calculated.</param> 928 /// <returns>A new DbFunctionExpression that returns the month difference between <param name="dateValue1"> and <param name="dateValue2">.</returns> 929 /// <exception cref="ArgumentNullException"><paramref name="dateValue1"/> or <paramref name="dateValue2"/> is null.</exception> 930 /// <exception cref="ArgumentException">No overload of the canonical 'DiffMonths' function accepts arguments with the result types of <paramref name="dateValue1"/> and <paramref name="dateValue2"/>.</exception> DiffMonths(this DbExpression dateValue1, DbExpression dateValue2)931 public static DbFunctionExpression DiffMonths(this DbExpression dateValue1, DbExpression dateValue2) 932 { 933 EntityUtil.CheckArgumentNull(dateValue1, "dateValue1"); 934 EntityUtil.CheckArgumentNull(dateValue2, "dateValue2"); 935 return InvokeCanonicalFunction("DiffMonths", dateValue1, dateValue2); 936 } 937 938 /// <summary> 939 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffDays' function with the 940 /// specified arguments, which must each have a DateTime or DateTimeOffset result type. The result type of 941 /// <paramref name="dateValue1"/> must match the result type of <paramref name="dateValue2"/>. 942 /// The result type of the expression is Edm.Int32. 943 /// </summary> 944 /// <param name="dateValue1">An expression that specifies the first DateTime or DateTimeOffset value.</param> 945 /// <param name="dateValue2">An expression that specifies the DateTime or DateTimeOffset for which the day difference from <paramref name="dateValue1"/> should be calculated.</param> 946 /// <returns>A new DbFunctionExpression that returns the day difference between <param name="dateValue1"> and <param name="dateValue2">.</returns> 947 /// <exception cref="ArgumentNullException"><paramref name="dateValue1"/> or <paramref name="dateValue2"/> is null.</exception> 948 /// <exception cref="ArgumentException">No overload of the canonical 'DiffDays' function accepts arguments with the result types of <paramref name="dateValue1"/> and <paramref name="dateValue2"/>.</exception> DiffDays(this DbExpression dateValue1, DbExpression dateValue2)949 public static DbFunctionExpression DiffDays(this DbExpression dateValue1, DbExpression dateValue2) 950 { 951 EntityUtil.CheckArgumentNull(dateValue1, "dateValue1"); 952 EntityUtil.CheckArgumentNull(dateValue2, "dateValue2"); 953 return InvokeCanonicalFunction("DiffDays", dateValue1, dateValue2); 954 } 955 956 /// <summary> 957 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffHours' function with the 958 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 959 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 960 /// The result type of the expression is Edm.Int32. 961 /// </summary> 962 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 963 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the hour difference from <paramref name="timeValue1"/> should be calculated.</param> 964 /// <returns>A new DbFunctionExpression that returns the hour difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 965 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 966 /// <exception cref="ArgumentException">No overload of the canonical 'DiffHours' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffHours(this DbExpression timeValue1, DbExpression timeValue2)967 public static DbFunctionExpression DiffHours(this DbExpression timeValue1, DbExpression timeValue2) 968 { 969 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 970 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 971 return InvokeCanonicalFunction("DiffHours", timeValue1, timeValue2); 972 } 973 974 /// <summary> 975 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffMinutes' function with the 976 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 977 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 978 /// The result type of the expression is Edm.Int32. 979 /// </summary> 980 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 981 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the minute difference from <paramref name="timeValue1"/> should be calculated.</param> 982 /// <returns>A new DbFunctionExpression that returns the minute difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 983 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 984 /// <exception cref="ArgumentException">No overload of the canonical 'DiffMinutes' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffMinutes(this DbExpression timeValue1, DbExpression timeValue2)985 public static DbFunctionExpression DiffMinutes(this DbExpression timeValue1, DbExpression timeValue2) 986 { 987 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 988 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 989 return InvokeCanonicalFunction("DiffMinutes", timeValue1, timeValue2); 990 } 991 992 /// <summary> 993 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffSeconds' function with the 994 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 995 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 996 /// The result type of the expression is Edm.Int32. 997 /// </summary> 998 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 999 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the second difference from <paramref name="timeValue1"/> should be calculated.</param> 1000 /// <returns>A new DbFunctionExpression that returns the second difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 1001 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 1002 /// <exception cref="ArgumentException">No overload of the canonical 'DiffSeconds' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffSeconds(this DbExpression timeValue1, DbExpression timeValue2)1003 public static DbFunctionExpression DiffSeconds(this DbExpression timeValue1, DbExpression timeValue2) 1004 { 1005 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 1006 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 1007 return InvokeCanonicalFunction("DiffSeconds", timeValue1, timeValue2); 1008 } 1009 1010 /// <summary> 1011 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffMilliseconds' function with the 1012 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 1013 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 1014 /// The result type of the expression is Edm.Int32. 1015 /// </summary> 1016 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 1017 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the millisecond difference from <paramref name="timeValue1"/> should be calculated.</param> 1018 /// <returns>A new DbFunctionExpression that returns the millisecond difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 1019 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 1020 /// <exception cref="ArgumentException">No overload of the canonical 'DiffMilliseconds' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffMilliseconds(this DbExpression timeValue1, DbExpression timeValue2)1021 public static DbFunctionExpression DiffMilliseconds(this DbExpression timeValue1, DbExpression timeValue2) 1022 { 1023 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 1024 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 1025 return InvokeCanonicalFunction("DiffMilliseconds", timeValue1, timeValue2); 1026 } 1027 1028 /// <summary> 1029 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffMicroseconds' function with the 1030 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 1031 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 1032 /// The result type of the expression is Edm.Int32. 1033 /// </summary> 1034 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 1035 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the microsecond difference from <paramref name="timeValue1"/> should be calculated.</param> 1036 /// <returns>A new DbFunctionExpression that returns the microsecond difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 1037 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 1038 /// <exception cref="ArgumentException">No overload of the canonical 'DiffMicroseconds' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffMicroseconds(this DbExpression timeValue1, DbExpression timeValue2)1039 public static DbFunctionExpression DiffMicroseconds(this DbExpression timeValue1, DbExpression timeValue2) 1040 { 1041 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 1042 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 1043 return InvokeCanonicalFunction("DiffMicroseconds", timeValue1, timeValue2); 1044 } 1045 1046 /// <summary> 1047 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'DiffNanoseconds' function with the 1048 /// specified arguments, which must each have a DateTime, DateTimeOffset or Time result type. The result type of 1049 /// <paramref name="timeValue1"/> must match the result type of <paramref name="timeValue2"/>. 1050 /// The result type of the expression is Edm.Int32. 1051 /// </summary> 1052 /// <param name="timeValue1">An expression that specifies the first DateTime, DateTimeOffset or Time value.</param> 1053 /// <param name="timeValue2">An expression that specifies the DateTime, DateTimeOffset or Time for which the nanosecond difference from <paramref name="timeValue1"/> should be calculated.</param> 1054 /// <returns>A new DbFunctionExpression that returns the nanosecond difference between <param name="timeValue1"> and <param name="timeValue2">.</returns> 1055 /// <exception cref="ArgumentNullException"><paramref name="timeValue1"/> or <paramref name="timeValue2"/> is null.</exception> 1056 /// <exception cref="ArgumentException">No overload of the canonical 'DiffNanoseconds' function accepts arguments with the result types of <paramref name="timeValue1"/> and <paramref name="timeValue2"/>.</exception> DiffNanoseconds(this DbExpression timeValue1, DbExpression timeValue2)1057 public static DbFunctionExpression DiffNanoseconds(this DbExpression timeValue1, DbExpression timeValue2) 1058 { 1059 EntityUtil.CheckArgumentNull(timeValue1, "timeValue1"); 1060 EntityUtil.CheckArgumentNull(timeValue2, "timeValue2"); 1061 return InvokeCanonicalFunction("DiffNanoseconds", timeValue1, timeValue2); 1062 } 1063 1064 #endregion 1065 1066 #region Math functions - Floor, Ceiling, Round, Truncate, Abs, Power 1067 1068 /// <summary> 1069 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Round' function with the 1070 /// specified argument, which must each have a single, double or decimal result type. The result 1071 /// type of the expression is the same as the result type of <paramref name="value"/>. 1072 /// </summary> 1073 /// <param name="value">An expression that specifies the numeric value to round.</param> 1074 /// <returns>A new DbFunctionExpression that rounds the specified argument to the nearest integer value.</returns> 1075 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception> 1076 /// <exception cref="ArgumentException">No overload of the canonical 'Round' function accepts an argument with the result type of <paramref name="value"/>.</exception> Round(this DbExpression value)1077 public static DbFunctionExpression Round(this DbExpression value) 1078 { 1079 EntityUtil.CheckArgumentNull(value, "value"); 1080 return InvokeCanonicalFunction("Round", value); 1081 } 1082 1083 /// <summary> 1084 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Round' function with the 1085 /// specified arguments, which must have a single, double or decimal, and integer result types. The result 1086 /// type of the expression is the same as the result type of <paramref name="value"/>. 1087 /// </summary> 1088 /// <param name="value">An expression that specifies the numeric value to round.</param> 1089 /// <param name="digits">An expression that specifies the number of digits of precision to use when rounding.</param> 1090 /// <returns>A new DbFunctionExpression that rounds the specified argument to the nearest integer value, with precision as specified by <paramref name="digits"/>.</returns> 1091 /// <exception cref="ArgumentNullException"><paramref name="value"/> or <paramref name="digits"/> is null.</exception> 1092 /// <exception cref="ArgumentException">No overload of the canonical 'Round' function accepts arguments with the result types of <paramref name="value"/> and <paramref name="digits"/>.</exception> Round(this DbExpression value, DbExpression digits)1093 public static DbFunctionExpression Round(this DbExpression value, DbExpression digits) 1094 { 1095 EntityUtil.CheckArgumentNull(value, "value"); 1096 EntityUtil.CheckArgumentNull(digits, "digits"); 1097 return InvokeCanonicalFunction("Round", value, digits); 1098 } 1099 1100 /// <summary> 1101 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Floor' function with the 1102 /// specified argument, which must each have a single, double or decimal result type. The result 1103 /// type of the expression is the same as the result type of <paramref name="value"/>. 1104 /// </summary> 1105 /// <param name="value">An expression that specifies the numeric value.</param> 1106 /// <returns>A new DbFunctionExpression that returns the largest integer value not greater than <paramref name="value"/>.</returns> 1107 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception> 1108 /// <exception cref="ArgumentException">No overload of the canonical 'Floor' function accepts an argument with the result type of <paramref name="value"/>.</exception> Floor(this DbExpression value)1109 public static DbFunctionExpression Floor(this DbExpression value) 1110 { 1111 EntityUtil.CheckArgumentNull(value, "value"); 1112 return InvokeCanonicalFunction("Floor", value); 1113 } 1114 1115 /// <summary> 1116 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Ceiling' function with the 1117 /// specified argument, which must each have a single, double or decimal result type. The result 1118 /// type of the expression is the same as the result type of <paramref name="value"/>. 1119 /// </summary> 1120 /// <param name="value">An expression that specifies the numeric value.</param> 1121 /// <returns>A new DbFunctionExpression that returns the smallest integer value not less than than <paramref name="value"/>.</returns> 1122 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception> 1123 /// <exception cref="ArgumentException">No overload of the canonical 'Ceiling' function accepts an argument with the result type of <paramref name="value"/>.</exception> Ceiling(this DbExpression value)1124 public static DbFunctionExpression Ceiling(this DbExpression value) 1125 { 1126 EntityUtil.CheckArgumentNull(value, "value"); 1127 return InvokeCanonicalFunction("Ceiling", value); 1128 } 1129 1130 /// <summary> 1131 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Abs' function with the 1132 /// specified argument, which must each have a numeric result type. The result 1133 /// type of the expression is the same as the result type of <paramref name="value"/>. 1134 /// </summary> 1135 /// <param name="value">An expression that specifies the numeric value.</param> 1136 /// <returns>A new DbFunctionExpression that returns the absolute value of <paramref name="value"/>.</returns> 1137 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception> 1138 /// <exception cref="ArgumentException">No overload of the canonical 'Abs' function accepts an argument with the result type of <paramref name="value"/>.</exception> Abs(this DbExpression value)1139 public static DbFunctionExpression Abs(this DbExpression value) 1140 { 1141 EntityUtil.CheckArgumentNull(value, "value"); 1142 return InvokeCanonicalFunction("Abs", value); 1143 } 1144 1145 /// <summary> 1146 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Truncate' function with the 1147 /// specified arguments, which must have a single, double or decimal, and integer result types. The result 1148 /// type of the expression is the same as the result type of <paramref name="value"/>. 1149 /// </summary> 1150 /// <param name="value">An expression that specifies the numeric value to truncate.</param> 1151 /// <param name="digits">An expression that specifies the number of digits of precision to use when truncating.</param> 1152 /// <returns>A new DbFunctionExpression that truncates the specified argument to the nearest integer value, with precision as specified by <paramref name="digits"/>.</returns> 1153 /// <exception cref="ArgumentNullException"><paramref name="value"/> <paramref name="digits"/> is null.</exception> 1154 /// <exception cref="ArgumentException">No overload of the canonical 'Truncate' function accepts arguments with the result types of <paramref name="value"/> and <paramref name="digits"/>.</exception> Truncate(this DbExpression value, DbExpression digits)1155 public static DbFunctionExpression Truncate(this DbExpression value, DbExpression digits) 1156 { 1157 EntityUtil.CheckArgumentNull(value, "value"); 1158 EntityUtil.CheckArgumentNull(digits, "digits"); 1159 return InvokeCanonicalFunction("Truncate", value, digits); 1160 } 1161 1162 /// <summary> 1163 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'Power' function with the 1164 /// specified arguments, which must have numeric result types. The result type of the expression is 1165 /// the same as the result type of <paramref name="baseArgument"/>. 1166 /// </summary> 1167 /// <param name="baseArgument">An expression that specifies the numeric value to raise to the given power.</param> 1168 /// <param name="exponent">An expression that specifies the power to which <paramref name="baseArgument"/> should be raised.</param> 1169 /// <returns>A new DbFunctionExpression that returns the value of <paramref name="baseArgument"/> raised to the power specified by <paramref name="exponent"/>.</returns> 1170 /// <exception cref="ArgumentNullException"><paramref name="baseArgument"/> <paramref name="exponent"/> is null.</exception> 1171 /// <exception cref="ArgumentException">No overload of the canonical 'Power' function accepts arguments with the result types of <paramref name="baseArgument"/> and <paramref name="exponent"/>.</exception> Power(this DbExpression baseArgument, DbExpression exponent)1172 public static DbFunctionExpression Power(this DbExpression baseArgument, DbExpression exponent) 1173 { 1174 EntityUtil.CheckArgumentNull(baseArgument, "baseArgument"); 1175 EntityUtil.CheckArgumentNull(exponent, "exponent"); 1176 return InvokeCanonicalFunction("Power", baseArgument, exponent); 1177 } 1178 1179 #endregion 1180 1181 #region Bitwise functions - And, Or, Not, Xor 1182 1183 /// <summary> 1184 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'BitwiseAnd' function with the 1185 /// specified arguments, which must have the same integer numeric result type. The result type of the 1186 /// expression is this same type. 1187 /// </summary> 1188 /// <param name="value">An expression that specifies the first operand.</param> 1189 /// <param name="value2">An expression that specifies the second operand.</param> 1190 /// <returns>A new DbFunctionExpression that returns the value produced by performing the bitwise AND of <paramref name="value1"/> and <paramref name="value2"/>.</returns> 1191 /// <exception cref="ArgumentNullException"><paramref name="value1"/> <paramref name="value2"/> is null.</exception> 1192 /// <exception cref="ArgumentException">No overload of the canonical 'BitwiseAnd' function accepts arguments with the result types of <paramref name="value1"/> and <paramref name="value2"/>.</exception> BitwiseAnd(this DbExpression value1, DbExpression value2)1193 public static DbFunctionExpression BitwiseAnd(this DbExpression value1, DbExpression value2) 1194 { 1195 EntityUtil.CheckArgumentNull(value1, "value1"); 1196 EntityUtil.CheckArgumentNull(value2, "value2"); 1197 return InvokeCanonicalFunction("BitwiseAnd", value1, value2); 1198 } 1199 1200 /// <summary> 1201 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'BitwiseOr' function with the 1202 /// specified arguments, which must have the same integer numeric result type. The result type of the 1203 /// expression is this same type. 1204 /// </summary> 1205 /// <param name="value1">An expression that specifies the first operand.</param> 1206 /// <param name="value2">An expression that specifies the second operand.</param> 1207 /// <returns>A new DbFunctionExpression that returns the value produced by performing the bitwise OR of <paramref name="value1"/> and <paramref name="value2"/>.</returns> 1208 /// <exception cref="ArgumentNullException"><paramref name="value1"/> <paramref name="value2"/> is null.</exception> 1209 /// <exception cref="ArgumentException">No overload of the canonical 'BitwiseOr' function accepts arguments with the result types of <paramref name="value1"/> and <paramref name="value2"/>.</exception> BitwiseOr(this DbExpression value1, DbExpression value2)1210 public static DbFunctionExpression BitwiseOr(this DbExpression value1, DbExpression value2) 1211 { 1212 EntityUtil.CheckArgumentNull(value1, "value1"); 1213 EntityUtil.CheckArgumentNull(value2, "value2"); 1214 return InvokeCanonicalFunction("BitwiseOr", value1, value2); 1215 } 1216 1217 /// <summary> 1218 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'BitwiseNot' function with the 1219 /// specified argument, which must have an integer numeric result type. The result type of the expression 1220 /// is this same type. 1221 /// </summary> 1222 /// <param name="value">An expression that specifies the first operand.</param> 1223 /// <returns>A new DbFunctionExpression that returns the value produced by performing the bitwise NOT of <paramref name="value"/>.</returns> 1224 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception> 1225 /// <exception cref="ArgumentException">No overload of the canonical 'BitwiseNot' function accepts an argument with the result type of <paramref name="value"/>.</exception> BitwiseNot(this DbExpression value)1226 public static DbFunctionExpression BitwiseNot(this DbExpression value) 1227 { 1228 EntityUtil.CheckArgumentNull(value, "value"); 1229 return InvokeCanonicalFunction("BitwiseNot", value); 1230 } 1231 1232 /// <summary> 1233 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'BitwiseXor' function with the 1234 /// specified arguments, which must have the same integer numeric result type. The result type of the 1235 /// expression is this same type. 1236 /// </summary> 1237 /// <param name="value1">An expression that specifies the first operand.</param> 1238 /// <param name="value2">An expression that specifies the second operand.</param> 1239 /// <returns>A new DbFunctionExpression that returns the value produced by performing the bitwise XOR (exclusive OR) of <paramref name="value1"/> and <paramref name="value2"/>.</returns> 1240 /// <exception cref="ArgumentNullException"><paramref name="value1"/> <paramref name="value2"/> is null.</exception> 1241 /// <exception cref="ArgumentException">No overload of the canonical 'BitwiseXor' function accepts arguments with the result types of <paramref name="value1"/> and <paramref name="value2"/>.</exception> BitwiseXor(this DbExpression value1, DbExpression value2)1242 public static DbFunctionExpression BitwiseXor(this DbExpression value1, DbExpression value2) 1243 { 1244 EntityUtil.CheckArgumentNull(value1, "value1"); 1245 EntityUtil.CheckArgumentNull(value2, "value2"); 1246 return InvokeCanonicalFunction("BitwiseXor", value1, value2); 1247 } 1248 1249 #endregion 1250 1251 #region GUID Generation - NewGuid 1252 1253 /// <summary> 1254 /// Creates a <see cref="DbFunctionExpression"/> that invokes the canonical 'NewGuid' function. 1255 /// </summary> 1256 /// <returns>A new DbFunctionExpression that returns a new GUID value.</returns> NewGuid()1257 public static DbFunctionExpression NewGuid() 1258 { 1259 return InvokeCanonicalFunction("NewGuid"); 1260 } 1261 1262 #endregion 1263 } 1264 } 1265