Mapování funkcí zprostředkovatele Microsoft SQL Serveru
Tato stránka ukazuje, které členy .NET jsou přeloženy do kterých funkcí SQL při použití zprostředkovatele SQL Serveru.
Agregační funkce
.NET | SQL | Přidáno do |
---|---|---|
EF. Functions.StandardDeviationSample(group. Select(x => x.Property)) | STDEV(Vlastnost) | EF Core 7.0 |
EF. Functions.StandardDeviationPopulation(group. Select(x => x.Property)) | STDEVP(Vlastnost) | EF Core 7.0 |
EF. Functions.VarianceSample(group. Select(x => x.Property)) | VAR(– vlastnost) | EF Core 7.0 |
EF. Functions.VariancePopulation(group. Select(x => x.Property)) | VARP(Vlastnost) | EF Core 7.0 |
skupina. Average(x => x.Property) | AVG(Vlastnost) | |
skupina. Count() | COUNT(*) | |
skupina. LongCount() | COUNT_BIG(*) | |
skupina. Max(x => x.Property) | MAX(Vlastnost) | |
skupina. Min(x => x.Property) | MIN(Vlastnost) | |
skupina. Sum(x => x.Property) | SUMA(Vlastnost) | |
řetězec. Concat(skupina. Select(x => x.Property)) | STRING_AGG(Vlastnost, N') | EF Core 7.0 |
řetězec. Join(oddělovač, skupina. Select(x => x.Property)) | STRING_AGG(vlastnost; @separator) | EF Core 7.0 |
Binární funkce
.NET | SQL | Přidáno do |
---|---|---|
byty. Contains(value) | CHARINDEX(@value; @bytes)> 0 | |
byty. ElementAt(i) | SUBSTRING(@bytes; @i + 1; 1) | EF Core 8.0 |
byty. First() | PODŘETĚŽKA(@bytes; 1; 1) | |
byty. Délka | DATALENGTH(@bytes) | |
byty. SequenceEqual(druhý) | @bytes = @second | |
bytes[i] | SUBSTRING(@bytes; @i + 1; 1) | |
EF. Functions.DataLength(arg) | DATALENGTH(@arg) |
Převodní funkce
.NET | SQL | Přidáno do |
---|---|---|
byty. ToString() | CONVERT(varchar(100); @bytes) | |
byteValue.ToString() | CONVERT(varchar(3); @byteValue) | |
charValue.ToString() | CONVERT(varchar(1); @charValue) | |
Convert.ToBoolean(value) | CONVERT(bit, @value) | |
Convert.ToByte(value) | CONVERT(tinyint; @value) | |
Convert.ToDecimal(value) | CONVERT(desítkové(18; 2); @value) | |
Convert.ToDouble(value) | CONVERT(float; @value) | |
Convert.ToInt16(value) | CONVERT(smallint; @value) | |
Convert.ToInt32(value) | CONVERT(int; @value) | |
Convert.ToInt64(value) | CONVERT(bigint, @value) | |
Convert.ToString(hodnota) | CONVERT(nvarchar(max); @value) | |
dateOnly.ToString() | CONVERT(varchar(100); @dateOnly) | EF Core 8.0 |
dateTime.ToString() | CONVERT(varchar(100); @dateTime) | |
dateTimeOffset.ToString() | CONVERT(varchar(100); @dateTimeOffset) | |
decimalValue.ToString() | CONVERT(varchar(100); @decimalValue) | |
doubleValue.ToString() | CONVERT(varchar(100); @doubleValue) | |
floatValue.ToString() | CONVERT(varchar(100); @floatValue) | |
identifikátor guid. ToString() | CONVERT(varchar(36); @guid) | |
intValue.ToString() | CONVERT(varchar(11); @intValue) | |
longValue.ToString() | CONVERT(varchar(20); @longValue) | |
sbyteValue.ToString() | CONVERT(varchar(4); @sbyteValue) | |
shortValue.ToString() | CONVERT(varchar(6); @shortValue) | |
timeOnly.ToString() | CONVERT(varchar(100); @timeOnly) | EF Core 8.0 |
timeSpan.ToString() | CONVERT(varchar(100); @timeSpan) | |
uintValue.ToString() | CONVERT(varchar(10); @uintValue) | |
ulongValue.ToString() | CONVERT(varchar(19); @ulongValue) | |
ushortValue.ToString() | CONVERT(varchar(5); @ushortValue) |
Funkce pro datum a čas
.NET | SQL | Přidáno do |
---|---|---|
DateTime.Now | GETDATE() | |
DateTime.Today | CONVERT(date; GETDATE()) | |
DateTime.UtcNow | GETUTCDATE() | |
dateTime.AddDays(value) | DATEADD(den, @value, @dateTime) | |
dateTime.AddHours(value) | DATEADD(hodina, @value, @dateTime) | |
dateTime.AddMilliseconds(value) | DATEADD(milisekunda, @value, @dateTime) | |
dateTime.AddMinutes(hodnota) | DATEADD(minuta, @value, @dateTime) | |
dateTime.AddMonths(months) | DATEADD(měsíc, @months, @dateTime) | |
dateTime.AddSeconds(value) | DATEADD(sekunda, @value, @dateTime) | |
dateTime.AddYears(value) | DATEADD(rok, @value, @dateTime) | |
dateTime.Date | CONVERT(datum, @dateTime) | |
dateTime.Day | DATEPART(den, @dateTime) | |
dateTime.DayOfYear | DATEPART(dayofyear, @dateTime) | |
dateTime.Hour | DATEPART(hodina, @dateTime) | |
dateTime.Millisecond | DATEPART(milisekunda, @dateTime) | |
dateTime.Minute | DATEPART(minuta; @dateTime) | |
dateTime.Month | DATEPART(měsíc, @dateTime) | |
dateTime.Second | DATEPART(sekunda; @dateTime) | |
dateTime.TimeOfDay | CONVERT(time; @dateTime) | |
dateTime.Year | DATEPART(rok, @dateTime) | |
DateTimeOffset.Now | SYSDATETIMEOFFSET() | |
DateTimeOffset.UtcNow | SYSUTCDATETIME() | |
dateTimeOffset.AddDays(days) | DATEADD(den, @days, @dateTimeOffset) | |
dateTimeOffset.AddHours(hours) | DATEADD(hodina, @hours, @dateTimeOffset) | |
dateTimeOffset.AddMilliseconds(milisekundy) | DATEADD(milisekunda, @milliseconds, @dateTimeOffset) | |
dateTimeOffset.AddMinutes(minutes) | DATEADD(minuta, @minutes, @dateTimeOffset) | |
dateTimeOffset.AddMonths(months) | DATEADD(měsíc, @months, @dateTimeOffset) | |
dateTimeOffset.AddSeconds(seconds) | DATEADD(sekunda, @seconds, @dateTimeOffset) | |
dateTimeOffset.AddYears(roky) | DATEADD(rok, @years, @dateTimeOffset) | |
dateTimeOffset.Date | CONVERT(datum, @dateTimeOffset) | |
dateTimeOffset.Day | DATEPART(den, @dateTimeOffset) | |
dateTimeOffset.DayOfYear | DATEPART(dayofyear, @dateTimeOffset) | |
dateTimeOffset.Hour | DATEPART(hodina, @dateTimeOffset) | |
dateTimeOffset.Millisecond | DATEPART(milisekunda, @dateTimeOffset) | |
dateTimeOffset.Minute | DATEPART(minuta; @dateTimeOffset) | |
dateTimeOffset.Month | DATEPART(měsíc, @dateTimeOffset) | |
dateTimeOffset.Second | DATEPART(sekunda; @dateTimeOffset) | |
dateTimeOffset.TimeOfDay | CONVERT(time; @dateTimeOffset) | |
dateTimeOffset.TounixTimeSeconds() | DATEDIFF_BIG(druhý; '1970-01-01T00:00:00.000000+00:00', @dateTimeOffset) | EF Core 8.0 |
dateTimeOffset.TounixTimeMilliseconds() | DATEDIFF_BIG(milisekundy; '1970-01-01T00:00:00.000000+00:00', @dateTimeOffset) | EF Core 8.0 |
dateTimeOffset.Year | DATEPART(rok, @dateTimeOffset) | |
DateOnly.FromDateTime(dateTime) | CONVERT(datum, @dateTime) | EF Core 8.0 |
dateOnly.AddDays(value) | DATEADD(den, @value, @dateOnly) | EF Core 8.0 |
dateOnly.AddMonths(months) | DATEADD(měsíc, @months, @dateOnly) | EF Core 8.0 |
dateOnly.AddYears(value) | DATEADD(rok, @value, @dateOnly) | EF Core 8.0 |
dateOnly.Day | DATEPART(den, @dateOnly) | EF Core 8.0 |
dateOnly.DayOfYear | DATEPART(dayofyear, @dateOnly) | EF Core 8.0 |
dateOnly.Month | DATEPART(měsíc, @dateOnly) | EF Core 8.0 |
dateOnly.Year | DATEPART(rok, @dateOnly) | EF Core 8.0 |
EF. Functions.AtTimeZone(dateTime, timeZone) | @dateTime V ČASOVÉM PÁSMU @timeZone | EF Core 7.0 |
EF. Functions.DateDiffDay(start, end) | DATEDIFF(den, @start, @end) | |
EF. Functions.DateDiffHour(start, end) | DATEDIFF(hodina, @start, @end) | |
EF. Functions.DateDiffMicrosecond(začátek, konec) | DATEDIFF(mikrosekundy, @start, @end) | |
EF. Functions.DateDiffMillisecond(začátek, konec) | DATEDIFF(milisekundy, @start, @end) | |
EF. Functions.DateDiffMinute(start, end) | DATEDIFF(minuta, @start, @d2) | |
EF. Functions.DateDiffMonth(start, end) | DATEDIFF(měsíc, @start, @end) | |
EF. Functions.DateDiffNanosecond(start, end) | DATEDIFF(nanosecond, @start, @end) | |
EF. Functions.DateDiffSecond(začátek, konec) | DATEDIFF(sekunda, @start, @end) | |
EF. Functions.DateDiffWeek(start, end) | DATEDIFF(týden, @start, @end) | |
EF. Functions.DateDiffYear(start, end) | DATEDIFF(rok, @start, @end) | |
EF. Functions.DateFromParts(rok, měsíc, den) | DATEFROMPARTS(@year; @month, @day) | |
EF. Functions.DateTime2FromParts(rok, měsíc, den, ...) | DATETIME2FROMPARTS(@year; @month, @day...) | |
EF. Functions.DateTimeFromParts(year, month, day, ...) | DATETIMEFROMPARTS(@year; @month, @day...) | |
EF. Functions.DateTimeOffsetFromParts(year, month, day, ...) | DATETIMEOFFSETFROMPARTS(@year, @month, @day...) | |
EF. Functions.IsDate(výraz) | ISDATE(@expression) | |
EF. Functions.SmallDateTimeFromParts(rok, měsíc, den, ...) | SMALLDATETIMEFROMPARTS(@year, @month, @day...) | |
EF. Functions.TimeFromParts(hodina, minuta, sekunda, ...) | TIMEFROMPARTS(@hour; @minute; @second...) | |
timeOnly.AddHours(value) | DATEADD(hodina, @value, @timeOnly) | EF Core 8.0 |
timeOnly.AddMinutes(value) | DATEADD(minuta, @value, @timeOnly) | EF Core 8.0 |
timeOnly.Hour | DATEPART(hodina, @timeOnly) | EF Core 8.0 |
timeOnly.IsBetween(start, end) | @timeOnly>= @start AND @timeOnly<@end | EF Core 8.0 |
timeOnly.Millisecond | DATEPART(milisekunda, @timeOnly) | EF Core 8.0 |
timeOnly.Minute | DATEPART(minuta; @timeOnly) | EF Core 8.0 |
timeOnly.Second | DATEPART(sekunda; @timeOnly) | EF Core 8.0 |
timeSpan.Hours | DATEPART(hodina, @timeSpan) | |
timeSpan.Milliseconds | DATEPART(milisekunda, @timeSpan) | |
timeSpan.Minutes | DATEPART(minuta; @timeSpan) | |
timeSpan.Seconds | DATEPART(sekunda; @timeSpan) |
Numerické funkce
.NET | SQL | Přidáno do |
---|---|---|
dvojitý. DegreesToRadians(x) | RADIANS(@x) | EF Core 8.0 |
dvojitý. RadiansToDegrees(x) | DEGREES(@x) | EF Core 8.0 |
EF. Functions.Random() | RAND() | |
Math.Abs(value) | ABS(@value) | |
Math.Acos(d) | ACOS(@d) | |
Math.Asin(d) | ASIN(@d) | |
Math.Atan(d) | ATAN(@d) | |
Math.Atan2(y, x) | ATN2(@y; @x) | |
Math.Ceiling(d) | CEILING(@d) | |
Math.Cos(d) | COS(@d) | |
Math.Exp(d) | EXP(@d) | |
Math.Floor(d) | FLOOR(@d) | |
Math.Log(d) | LOG(@d) | |
Math.Log(a, newBase) | LOG(@a; @newBase) | |
Math.Log10(d) | LOG10(@d) | |
Math.Max(x; y) | GREATEST(@x; @y) | EF Core 9.0 |
Math.Min(x; y) | LEAST(@x; @y) | EF Core 9.0 |
Math.Pow(x, y) | POWER(@x; @y) | |
Math.Round(d) | ROUND(@d; 0) | |
Math.Round(d, desetinná místa) | ROUND(@d; @decimals) | |
Math.Sign(value) | SIGN(@value) | |
Math.Sin(a) | SIN(@a) | |
Math.Sqrt(d) | SQRT(@d) | |
Math.Tan(a) | TAN(@a) | |
Math.Truncate(d) | ROUND(@d; 0; 1) |
Tip
Kromě zde uvedených metod jsou také přeloženy odpovídající obecné matematické implementace a metody MathF . Například , Math.Sin
, MathF.Sin
double.Sin
a float.Sin
všechny mapování na SIN
funkci v SQL.
Funkce řetězců
.NET | SQL | Přidáno do |
---|---|---|
EF. Functions.Collate(operand, kolace) | @operand KOLACIONOVAT @collation | |
EF. Functions.Contains(propertyReference, searchCondition) | CONTAINS(@propertyReference; @searchCondition) | |
EF. Functions.Contains(propertyReference, searchCondition, languageTerm) | CONTAINS(@propertyReference; @searchCondition, JAZYK @languageTerm) | |
EF. Functions.FreeText(propertyReference, freeText) | FREETEXT(@propertyReference; @freeText) | |
EF. Functions.FreeText(propertyReference, freeText, languageTerm) | FREETEXT(@propertyReference; @freeText, JAZYK @languageTerm) | |
EF. Functions.IsNumeric(expression) | ISNUMERIC(@expression) | |
EF. Functions.Like(matchExpression; pattern) | @matchExpression JAKO @pattern | |
EF. Functions.Like(matchExpression, pattern, escapeCharacter) | @matchExpression JAKO @pattern ESCAPE @escapeCharacter | |
řetězec. Compare(strA, strB) | CASE WHEN @strA = @strB THEN 0 ... KONEC | |
řetězec. Concat(str0, str1) | @str0 + @str1 | |
řetězec. IsNullOrEmpty(value) | @value JE NULL NEBO @value LIKE N' | |
řetězec. IsNullOrWhiteSpace(hodnota) | @value IS NULL OR @value = N'' | |
řetězec. Join("; ", new [] { x, y, z}) | CONCAT_WS(N', ', @x, @y, , @z) | EF Core 9.0 |
stringValue.CompareTo(strB) | CASE WHEN @stringValue = @strB THEN 0 ... KONEC | |
stringValue.Contains(value) | @stringValue LIKE N'%' + @value + N'%' | |
stringValue.EndsWith(value) | @stringValue LIKE N'%' + @value | |
stringValue.FirstOrDefault() | PODŘETĚŽCE(@stringValue; 1; 1) | |
stringValue.IndexOf(value) | CHARINDEX(@value; @stringValue) - 1 | |
stringValue.IndexOf(hodnota, startIndex) | CHARINDEX(@value; @stringValue, @startIndex) - 1 | EF Core 7.0 |
stringValue.LastOrDefault() | SUBSTRING(@stringValue; DÉLKA(@stringValue); 1) | |
stringValue.Length | DÉLKA(@stringValue) | |
stringValue.Replace(@oldValue; @newValue) | REPLACE(@stringValue; @oldValue, @newValue) | |
stringValue.StartsWith(value) | @stringValue LIKE @value + N'%' | |
stringValue.Substring(startIndex) | SUBSTRING(@stringValue; @startIndex + 1; DÉLKA(@stringValue)) | |
stringValue.Substring(startIndex; length) | PODŘETĚŽK(@stringValue; @startIndex + 1; @length) | |
stringValue.ToLower() | LOWER(@stringValue) | |
stringValue.Toupper() | UPPER(@stringValue) | |
stringValue.Trim() | LTRIM(RTRIM(@stringValue)) | |
stringValue.TrimEnd() | RTRIM(@stringValue) | |
stringValue.TrimStart() | LTRIM(@stringValue) |
Různé funkce
.NET | SQL |
---|---|
sbírka. Contains(item) | @item V @collection |
enumValue.HasFlag(flag) | @enumValue & @flag = @flag |
Guid.NewGuid() | NEWID() |
Nullable. GetValueOrDefault() | COALESCE(@nullable; 0) |
Nullable. GetValueOrDefault(defaultValue) | COALESCE(@nullable; @defaultValue) |
Poznámka:
Některé SQL byly zjednodušeny pro účely ilustrace. Skutečný SQL je složitější pro zpracování širšího rozsahu hodnot.
Viz také
Spolupracujte s námi na GitHubu
Zdroj tohoto obsahu najdete na GitHubu, kde můžete také vytvářet a kontrolovat problémy a žádosti o přijetí změn. Další informace najdete v našem průvodci pro přispěvatele.