From 5e7b898fa3edbe11603d379900bd2db7f07a21c3 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 2 Oct 2020 16:33:12 -0700 Subject: [PATCH] Document SQLite function mappings Part of #504 --- .../core/providers/sqlite/functions.md | 103 ++++++++++++++++++ .../core/providers/sqlite/spatial.md | 2 +- entity-framework/toc.yml | 2 + 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 entity-framework/core/providers/sqlite/functions.md diff --git a/entity-framework/core/providers/sqlite/functions.md b/entity-framework/core/providers/sqlite/functions.md new file mode 100644 index 0000000000..3dd51081d4 --- /dev/null +++ b/entity-framework/core/providers/sqlite/functions.md @@ -0,0 +1,103 @@ +--- +title: Function Mappings - SQLite Database Provider - EF Core +description: Function Mappings of the SQLite EF Core database provider +author: bricelam +ms.date: 10/05/2020 +uid: core/providers/sqlite/built-in-functions +--- +# Function Mappings of the SQLite EF Core Provider + +This table shows which .NET members are translated into which SQL functions when using the SQLite provider. + +## Binary functions + +.NET | SQL | Added in +--------------------- | ------------------------------- | -------- +bytes.Contains(value) | instr(@bytes, char(@value)) > 0 | EF Core 5.0 +bytes.Length | length(@bytes) | EF Core 5.0 + +## Date and time functions + +.NET | SQL | Added in +------------------------------- | ------------------------------------------------------------------------ | -------- +DateTime.Now | datetime('now', 'localtime') +DateTime.Today | datetime('now', 'localtime', 'start of day') +DateTime.UtcNow | datetime('now') +dateTime.AddDays(value) | datetime(@dateTime, @value \|\| ' days') +dateTime.AddHours(value) | datetime(@dateTime, @d \|\| ' hours') +dateTime.AddMilliseconds(value) | datetime(@dateTime, (@value / 1000.0) \|\| ' seconds') | EF Core 2.2 +dateTime.AddMinutes(value) | datetime(@dateTime, @value \|\| ' minutes') +dateTime.AddMonths(months) | datetime(@dateTime, @months \|\| ' months') +dateTime.AddSeconds(value) | datetime(@dateTime, @value \|\| ' seconds') +dateTime.AddTicks(value) | datetime(@dateTime, (@value / 10000000.0) \|\| ' seconds') | EF Core 2.2 +dateTime.AddYears(value) | datetime(@dateTime, @value \|\| ' years') +dateTime.Date | datetime(@dateTime, 'start of day') +dateTime.Day | strftime('%d', @dateTime) +dateTime.DayOfWeek | strftime('%w', @dateTime) | EF Core 2.2 +dateTime.DayOfYear | strftime('%j', @dateTime) +dateTime.Hour | strftime('%H', @dateTime) +dateTime.Millisecond | (strftime('%f', @dateTime) * 1000) % 1000 +dateTime.Minute | strftime('%M', @dateTime) +dateTime.Month | strftime('%m', @dateTime) +dateTime.Second | strftime('%S', @dateTime) +dateTime.Ticks | (julianday(@dateTime) - julianday('0001-01-01 00:00:00')) * 864000000000 | EF Core 2.2 +dateTime.TimeOfDay | time(@dateTime) | EF Core 3.0 +dateTime.Year | strftime('%Y', @dateTime) + +> [!NOTE] +> Some SQL has been simplified for illustration purposes. The actual SQL is more complex to handle a wider range of values. + +## Numeric functions + +.NET | SQL | Added in +--------------------- | ------------------------------------ | -------- +-decimalValue | ef_negate(@decimalValue) | EF Core 5.0 +decimalValue - d | ef_add(@decimalValue, ef_negate(@d)) | EF Core 5.0 +decimalValue * d | ef_multiply(@decimalValue, @d) | EF Core 5.0 +decimalValue / d | ef_divide(@decimalValue, @d) | EF Core 5.0 +decimalValue % d | ef_mod(@decimalValue, @d) | EF Core 5.0 +decimalValue + d | ef_add(@decimalValue, @d) | EF Core 5.0 +decimalValue < d | ef_compare(@decimalValue, @d) < 0 | EF Core 5.0 +decimalValue <= d | ef_compare(@decimalValue, @d) <= 0 | EF Core 5.0 +decimalValue > d | ef_compare(@decimalValue, @d) > 0 | EF Core 5.0 +decimalValue >= d | ef_compare(@decimalValue, @d) >= 0 | EF Core 5.0 +doubleValue % d | ef_mod(@doubleValue, @d) | EF Core 5.0 +floatValue % d | ef_mod(@floatValue, @d) | EF Core 5.0 +Math.Abs(value) | abs(@value) +Math.Max(val1, val2) | max(@val1, @val2) +Math.Min(val1, val2) | min(@val1, @val2) +Math.Round(d) | round(@d) +Math.Round(d, digits) | round(@d, @digits) + +> [!TIP] +> SQL functions prefixed with *ef* are created by EF Core. + +## String functions + +.NET | SQL | Added in +----------------------------------------- | ---------------------------------------------- | -------- +string.IsNullOrWhiteSpace(value) | @value IS NULL OR trim(@value) = '' +stringValue.Contains(value) | instr(@stringValue, @value) > 0 +stringValue.EndsWith(value) | @stringValue LIKE '%' \|\| @value +stringValue.FirstOrDefault() | substr(@stringValue, 1, 1) | EF Core 5.0 +stringValue.IndexOf(value) | instr(@stringValue, @value) - 1 +stringValue.LastOrDefault() | substr(@stringValue, length(@stringValue), 1) | EF Core 5.0 +stringValue.Length | length(@stringValue) +stringValue.Replace(oldValue, newValue) | replace(@stringValue, @oldValue, @newValue) +stringValue.StartsWith(value) | @stringValue LIKE @value \|\| '%' +stringValue.Substring(startIndex, length) | substr(@stringValue, @startIndex + 1, @length) +stringValue.ToLower() | lower(@stringValue) +stringValue.ToUpper() | upper(@stringValue) +stringValue.Trim() | trim(@stringValue) +stringValue.Trim(trimChar) | trim(@stringValue, @trimChar) +stringValue.TrimEnd() | rtrim(@stringValue) +stringValue.TrimEnd(trimChar) | rtrim(@stringValue, @trimChar) +stringValue.TrimStart() | ltrim(@stringValue) +stringValue.TrimStart(trimChar) | ltrim(@stringValue, @trimChar) + +> [!NOTE] +> Some SQL has been simplified for illustration purposes. The actual SQL is more complex to handle a wider range of values. + +## See also + +* [Spatial Function Mappings](xref:core/providers/sqlite/spatial#spatial-function-mappings) diff --git a/entity-framework/core/providers/sqlite/spatial.md b/entity-framework/core/providers/sqlite/spatial.md index e4e9f94443..6a759cca18 100644 --- a/entity-framework/core/providers/sqlite/spatial.md +++ b/entity-framework/core/providers/sqlite/spatial.md @@ -62,7 +62,7 @@ modelBuilder.Entity().Property(c => c.Location) .HasColumnType("POINTZ"); ``` -## Translated Operations +## Spatial Function Mappings This table shows which [NetTopologySuite](https://nettopologysuite.github.io/NetTopologySuite/) (NTS) members are translated into which SQL functions. diff --git a/entity-framework/toc.yml b/entity-framework/toc.yml index dded3c795d..d5bd0a485b 100644 --- a/entity-framework/toc.yml +++ b/entity-framework/toc.yml @@ -244,6 +244,8 @@ href: core/providers/sqlite/index.md - name: SQLite limitations href: core/providers/sqlite/limitations.md + - name: Built-in Functions + href: core/providers/sqlite/built-in-functions.md - name: Spatial data displayName: GIS href: core/providers/sqlite/spatial.md