Partilhar via


Mapeamentos de função do provedor do Microsoft SQL Server

Esta página mostra quais membros do .NET são convertidos em quais funções SQL ao usar o provedor do SQL Server.

Funções agregadas

.NET SQL Adicionado em
EF.Functions.StandardDeviationSample(grupo.Selecionar(x => x.Property)) STDEV(Propriedade) EF Núcleo 7.0
EF.Functions.StandardDeviationPopulation(group.Select(x => x.Property)) STDEVP(Propriedade) EF Núcleo 7.0
EF.Functions.VarianceSample(grupo.Selecionar(x => x.Property)) VAR (Propriedade) EF Núcleo 7.0
EF. Functions.VariancePopulation(grupo. Selecionar(x => x.Property)) VARP(Propriedade) EF Núcleo 7.0
grupo.média(x => x.Propriedade) AVG(Propriedade)
grupo. Contagem() CONTAGEM(*)
grupo.ContagemLonga() COUNT_BIG(*)
grupo.Max(x => x.Propriedade) MAX(Propriedade)
grupo.Min(x => x.Propriedade) MIN (Propriedade)
grupo.Soma(x => x.Propriedade) SOMA(Propriedade)
string.Concat(grupo.Select(x => x.Property)) STRING_AGG(Propriedade, N'') EF Núcleo 7.0
string.Join(separador, grupo.Select(x =>> x.Property)) STRING_AGG(Propriedade, @separator) EF Núcleo 7.0

Funções binárias

.NET SQL Adicionado em
bytes. Contém(valor) CHARINDEX(@value, @bytes)> 0
bytes.ElementAt(i) SUBSTRING(@bytes, @i + 1, 1) EF Core 8.0
bytes. Primeiro() SUBSTRING(@bytes, 1, 1)
bytes. Comprimento TAMANHO DOS DADOS(@bytes)
bytes.SequenceEqual(segundo) @bytes = @second
bytes[i] SUBSTRING(@bytes, @i + 1, 1)
EF.Funções.DataLength(arg) DATALENGTH(@arg)

Funções de conversão

.NET SQL Adicionado em
bytes.ToString() CONVERT(varchar(100), @bytes)
byteValue.ToString() CONVERT(varchar(3), @byteValue)
charValue.ToString() CONVERT(varchar(1), @charValue)
Convert.ToBoolean(valor) CONVERT(bit, @value)
Convert.ToByte(valor) CONVERT(tinyint, @value)
Convert.ToDecimal(valor) CONVERT(decimal(18, 2), @value)
Convert.ToDouble(valor) CONVERT(float, @value)
Convert.ToInt16(valor) CONVERT(smallint, @value)
Convert.ToInt32(valor) CONVERT(int, @value)
Convert.ToInt64(valor) CONVERT(bigint, @value)
Convert.ToString(valor) 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)
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)

Funções de data e hora

.NET SQL Adicionado em
DateTime.Now GETDATE()
DateTime.Today CONVERT(date, GETDATE())
DateTime.UtcNow GETUTCDATE()
dateTime.AddDays(valor) DATEADD(dia, @value, @dateTime)
dateTime.AddHours(valor) DATEADD(hora, @value, @dateTime)
dateTime.AddMilliseconds(valor) DATEADD(milissegundo, @value, @dateTime)
dateTime.AddMinutes(valor) DATEADD(minuto, @value, @dateTime)
dateTime.AddMonths(meses) DATEADD(mês, @months, @dateTime)
dateTime.AddSeconds(valor) DATEADD(segundo, @value, @dateTime)
dateTime.AddYears(valor) DATEADD(anos, @value, @dateTime)
dateTime.Date CONVERT(data, @dateTime)
dateTime.Day DATEPART(dia, @dateTime)
dateTime.DayOfYear DATEPART(diadoano, @dateTime)
dateTime.Hora DATEPART(hora, @dateTime)
dateTime.Microsecond DATEPART (microssegundo, @dateTime) % 1000 EF Core 10.0
dateTime.Millisecond DATEPART(milissegundo, @dateTime)
dateTime.Minute DATEPART(minuto, @dateTime)
dateTime.Mês DATEPART(mês, @dateTime)
dateTime.Nanosecond DATEPART(nanosegundo, @dateTime) % 1000 EF Core 10.0
dateTime.Second DATEPART(segundo, @dateTime)
dateTime.TimeOfDay CONVERT(tempo, @dateTime)
dateTime.Ano DATEPART(ano, @dateTime)
DateTimeOffset.Now SYSDATETIMEOFFSET()
DateTimeOffset.UtcNow SYSUTCDATETIME()
dateTimeOffset.AddDays(dias) DATEADD(dia, @days, @dateTimeOffset)
dateTimeOffset.AddHours(horas) DATEADD(hora, @hours, @dateTimeOffset)
dateTimeOffset.AddMilliseconds(milissegundos) DATEADD(milissegundo, @milliseconds, @dateTimeOffset)
dateTimeOffset.AddMinutes(minutos) DATEADD(minuto, @minutes, @dateTimeOffset))
dateTimeOffset.AddMonths(meses) DATEADD(mês, @months, @dateTimeOffset)
dateTimeOffset.AddSeconds(segundos) DATEADD(segundo, @seconds, @dateTimeOffset)
dateTimeOffset.AddYears(anos) DATEADD(ano, @years, @dateTimeOffset)
dateTimeOffset.Date CONVERT(data, @dateTimeOffset)
dateTimeOffset.Dia DATEPART(dia, @dateTimeOffset)
dateTimeOffset.DayOfYear DATEPART(dia_do_ano, @dateTimeOffset)
dateTimeOffset.Hour DATEPART(hora, @dateTimeOffset)
dateTimeOffset.Microsegundo DATEPART(microsegundo, @dateTimeOffset) % 1000) EF Core 10.0
dateTimeOffset.Millisecond DATEPART(milissegundo, @dateTimeOffset)
dateTimeOffset.Minuto DATEPART(minuto, @dateTimeOffset)
dateTimeOffset.Mês DATEPART(mês, @dateTimeOffset)
dateTimeOffset.Nanossegundo DATEPART(nanosegundo, @dateTimeOffset) % 1000) EF Core 10.0
dateTimeOffset.Second DATEPART(segundo, @dateTimeOffset)
dateTimeOffset.PeríodoDoDia CONVERT(tempo, @dateTimeOffset)
dateTimeOffset.ToUnixTimeSeconds() DATEDIFF_BIG(segundo, '1970-01-01T00:00:00.0000000+00:00', @dateTimeOffset) EF Core 8.0
dateTimeOffset.ToUnixTimeMilliseconds() DATEDIFF_BIG(milissegundo, '1970-01-01T00:00:00.0000000+00:00', @dateTimeOffset) EF Core 8.0
dateTimeOffset.Ano DATEPART(ano, @dateTimeOffset)
DateOnly.FromDateTime(dateTime) CONVERT(date, @dateTime) EF Core 8.0
dateOnly.AddDays(valor) DATEADD(dia, @value, @dateOnly) EF Core 8.0
dateOnly.AddMonths(meses) DATEADD(mês, @months, @dateOnly) EF Core 8.0
dateOnly.AddYears(valor) DATEADD(ano, @value, @dateOnly) EF Core 8.0
dateOnly.Day DATEPART(dia, @dateOnly) EF Core 8.0
dataApenas.DiaDoAno DATEPART(dia do ano, @dateOnly) EF Core 8.0
dateOnly.Mês DATEPART(mês, @dateOnly) EF Core 8.0
dateOnly.Ano DATEPART(ano, @dateOnly) EF Core 8.0
EF. Functions.AtTimeZone(dateTime, timeZone) @dateTime NO FUSO HORÁRIO @timeZone EF Núcleo 7.0
EF. Functions.DateDiffDay(início, fim) DATEDIFF(dia, @start, @end)
EF. Functions.DateDiffHour(início, fim) DATEDIFF(hora, @start, @end)
EF. Functions.DateDiffMicrosecond(início, fim) DATEDIFF(microsegundo, @start, @end)
EF. Functions.DateDiffMillisecond(início, fim) DATEDIFF(Milissegundo, @start, @end)
EF. Functions.DateDiffMinute(início, fim) DATEDIFF(minuto, @start, @d2)
EF. Functions.DateDiffMonth(início, fim) DATEDIFF(mês, @start, @end)
EF. Functions.DateDiffNanosecond (início, fim) DATEDIFF(nanosegundo, @start, @end)
EF.Functions.DateDiffSecond(início, fim) DATEDIFF(segundo, @start, @end)
EF. Functions.DateDiffWeek(início, fim) DATEDIFF(week, @start, @end)
EF. Functions.DateDiffYear(início, fim) DATEDIFF(year, @start, @end)
EF. Functions.DateFromParts(ano, mês, dia) DATEFROMPARTS(@year, @month, @day)
EF.Functions.DateTime2FromParts(ano, mês, dia, ...) DATETIME2FROMPARTS(@year, @month, @day, ...)
EF.Functions.DateTimeFromParts(ano, mês, dia, ...) DATETIMEFROMPARTS(@year, @month, @day, ...)
EF.Functions.DateTimeOffsetFromParts(ano, mês, dia, ...) DATETIMEOFFSETFROMPARTS(@year, @month, @day, ...)
EF.Functions.IsDate(expressão) ISDATE(@expression)
EF. Functions.SmallDateTimeFromParts (ano, mês, dia, ...) SMALLDATETIMEFROMPARTS(@year, @month, @day, ...)
EF.Functions.TimeFromParts(hora, minuto, segundo, ...) TIMEFROMPARTS(@hour, @minute, @second, ...)
timeOnly.AddHours(valor) DATEADD(hora, @value, @timeOnly) EF Core 8.0
timeOnly.AddMinutes(valor) DATEADD(minuto, @value, @timeOnly) EF Core 8.0
timeOnly.Hora DATEPART(hora, @timeOnly) EF Core 8.0
timeOnly.IsBetween(início, fim) @timeOnly >= @start E @timeOnly<@end EF Core 8.0
timeOnly.Microsecond DATEPART (microssegundo, @timeOnly) % 1000 EF Core 10.0
timeOnly.Milissegundo DATEPART(milissegundo, @timeOnly) EF Core 8.0
timeOnly.Minute DATEPART(minuto, @timeOnly) EF Core 8.0
timeOnly.Nanosecond DATEPART(nanosegundo, @timeOnly) % 1000 EF Core 10.0
timeOnly.Second DATEPART(segundo, @timeOnly) EF Core 8.0
intervaloDeTempo.Horas DATEPART(hora, @timeSpan)
timeSpan.Microsegundo DATEPART (microssegundo, @timeSpan) % 1000 EF Core 10.0
timeSpan.Milissegundos DATEPART(milissegundo, @timeSpan))
timeSpan.Minutos DATEPART(minuto, @timeSpan))
timeSpan.Nanosegundo DATEPART(nanosegundo, @timeSpan) % 1000 EF Core 10.0
timeSpan.Seconds DATEPART(segundo, @timeSpan)

Funções numéricas

.NET SQL Adicionado em
double.GrausParaRadianos(x) RADIANOS(@x) EF Core 8.0
double.RadiansToDegrees(x) GRAUS(@x) EF Core 8.0
EF.Functions.Random() RAND()
Math.Abs(valor) ABS(@value)
Math.Acos(d) ACOS(@d)
Math.Asin(d) ASIN(@d)
Math.Atan(d) ATAN(@d)
Math.Atan2(y, x) ATN2(@y, @x)
Matemática.Teto(d) ARREDONDAR PARA CIMA(@d)
Math.Cos(d) COS(@d)
Math.Exp(d) EXP(@d)
Math.Floor(d) ARREDONDAR.PARA.BAIXO(@d)
Math.Log(d) LOG(@d)
Math.Log(a, newBase) LOG(@a, @newBase)
Math.Log10(d) LOG10(@d)
Math.Max(x, y) MAIOR(@x, @y) EF Núcleo 9.0
Math.Min(x, y) MENOS(@x, @y) EF Núcleo 9.0
Math.Pow(x, y) POTÊNCIA(@x, @y)
Math.Round(d) RODADA(@d, 0)
Math.Round(d, decimais) REDONDO(@d, @decimals)
Math.Sign(valor) SINAL(@value)
Math.Sin(a) SEN(@a)
Math.Sqrt(d) SQRT(@d)
Math.Tan(a) TAN(@a)
Math.Truncate(d) ARREDONDAR(@d, 0, 1)

Dica

Além dos métodos listados aqui, implementações de matemáticas correspondentes genéricas e métodos de MathF também são traduzidos. Por exemplo, Math.Sin, MathF.Sin, double.Sine float.Sin todos mapeiam para a função SIN no SQL.

Funções de cadeia de caracteres

.NET SQL Adicionado em
EF. Functions.Collate(operando, agrupamento) @operand COLLATE @collation
EF.Functions.Contains(propertyReference, searchCondition) CONTÉM(@propertyReference, @searchCondition)
EF.Functions.Contains(propertyReference, searchCondition, languageTerm) CONTÉM(@propertyReference, @searchCondition, IDIOMA @languageTerm)
EF.Functions.FreeText(propertyReference, freeText) TEXTO LIVRE(@propertyReference, @freeText)
EF.Functions.FreeText(referênciaPropriedade, textoLivre, termoIdioma) FREETEXT(@propertyReference, @freeText, LANGUAGE @languageTerm)
EF.Functions.IsNumeric(expressão) ISNUMERIC(@expression)
EF.Functions.Like(matchExpression, padrão) @matchExpression GOSTO @pattern
EF.Functions.Like(matchExpression, pattern, escapeCharacter) @matchExpression COMO @pattern ESCAPE @escapeCharacter
string.Comparar(strA, strB) CASO SE @strA = @strB ENTÃO 0 ... FIM
string.Concat(str0, str1) @str0 + @str1
string.IsNullOrEmpty(valor) @value É NULO OU @value É SEMELHANTE A N''
string.IsNullOrWhiteSpace(valor) @value É NULO OU @value = N''
string.Join(", ", new[] { x, y, z}) CONCAT_WS(N', ', @x, @y, @z) EF Núcleo 9.0
stringValue.CompareTo(strB) CASO QUANDO @stringValue = @strB ENTÃO 0 ... FIM
stringValue.Contains(value) @stringValue GOSTO N'%' + @value + N'%'
stringValue.EndsWith(valor) @stringValue GOSTO N'%' + @value
stringValue.FirstOrDefault() SUBSTRING(@stringValue, 1, 1)
stringValue.IndexOf(value) CHARINDEX(@value, @stringValue) - 1
stringValue.IndexOf(valor, startIndex) CHARINDEX(@value, @stringValue, @startIndex) - 1 EF Núcleo 7.0
stringValue.LastOrDefault() SUBSTRING(@stringValue, LEN(@stringValue), 1)
stringValue.Length LEN(@stringValue)
stringValue.Replace(@oldValue, @newValue) SUBSTITUIR(@stringValue, @oldValue, @newValue)
stringValue.StartsWith(valor) @stringValue GOSTO @value + N'%'
stringValue.Substring(startIndex) SUBSTRING(@stringValue, @startIndex + 1, LEN(@stringValue))
stringValue.Substring(startIndex, comprimento) SUBSTRING(@stringValue, @startIndex + 1, @length)
stringValue.ToLower() INFERIOR(@stringValue)
stringValue.ToUpper() SUPERIOR(@stringValue)
stringValue.Trim() LTRIM(RTRIM(@stringValue))
stringValue.TrimEnd() RTRIM(@stringValue)
stringValue.TrimStart() LTRIM(@stringValue)

Funções diversas

.NET SQL Adicionado em
enumValue.HasFlag(indicador) @enumValue & @flag = @flag
Guid.NewGuid() NEWID()
nullable.GetValueOrDefault() COALESCE (@nullable, 0)
nulo.GetValueOrDefault(defaultValue) COALESCE(@nullable, @defaultValue)

Observação

Alguns SQL foram simplificados para fins de ilustração. O SQL real é mais complexo para lidar com uma gama mais ampla de valores.

Ver também