Skip to content

Commit

Permalink
Add EF7 function translations
Browse files Browse the repository at this point in the history
Resolves #3868
  • Loading branch information
bricelam committed Aug 29, 2022
1 parent c3d4ef9 commit 280c86b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
2 changes: 2 additions & 0 deletions entity-framework/core/providers/cosmos/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ MathF.Truncate(x) | TRUNC(@x) | EF Core 6.0

.NET | SQL | Added in
------------------------------------------------------------- | ---------------------------------------------------------- | --------
Regex.IsMatch(input, pattern) | RegexMatch(@pattern, @input) | EF Core 7.0
Regex.IsMatch(input, pattern, options) | RegexMatch(@input, @pattern, @options) | EF Core 7.0
string.Concat(str0, str1) | @str0 + @str1 | EF Core 6.0
string.Equals(a, b, StringComparison.Ordinal) | STRINGEQUALS(@a, @b) | EF Core 6.0
string.Equals(a, b, StringComparison.OrdinalIgnoreCase) | STRINGEQUALS(@a, @b, true) | EF Core 6.0
Expand Down
19 changes: 19 additions & 0 deletions entity-framework/core/providers/sql-server/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ uid: core/providers/sql-server/functions

This page shows which .NET members are translated into which SQL functions when using the SQL Server provider.

## Aggregate functions

.NET | SQL | Added in
----------------------------------------------------------------------- | -------------------------------- | --------
EF.Functions.StandardDeviationSample(group.Select(x => x.Property)) | STDEV(Property) | EF Core 7.0
EF.Functions.StandardDeviationPopulation(group.Select(x => x.Property)) | STDEVP(Property) | EF Core 7.0
EF.Functions.VarianceSample(group.Select(x => x.Property)) | VAR(Property) | EF Core 7.0
EF.Functions.VariancePopulation(group.Select(x => x.Property)) | VARP(Property) | EF Core 7.0
group.Average(x => x.Property) | AVG(Property)
group.Count() | COUNT(*)
group.LongCount() | COUNT_BIG(*)
group.Max(x => x.Property) | MAX(Property)
group.Min(x => x.Property) | MIN(Property)
group.Sum(x => x.Property) | SUM(Property)
string.Concat(group.Select(x => x.Property)) | STRING_AGG(Property, N'') | EF Core 7.0
string.Join(separator, group.Select(x => x.Property)) | STRING_AGG(Property, @separator) | EF Core 7.0

## Binary functions

.NET | SQL | Added in
Expand Down Expand Up @@ -93,6 +110,7 @@ dateTimeOffset.Month | DATEPART(month, @d
dateTimeOffset.Second | DATEPART(second, @dateTimeOffset)
dateTimeOffset.TimeOfDay | CONVERT(time, @dateTimeOffset)
dateTimeOffset.Year | DATEPART(year, @dateTimeOffset)
EF.Functions.AtTimeZone(dateTime, timeZone) | @dateTime AT TIME ZONE @timeZone | EF Core 7.0
EF.Functions.DateDiffDay(start, end) | DATEDIFF(day, @start, @end)
EF.Functions.DateDiffHour(start, end) | DATEDIFF(hour, @start, @end)
EF.Functions.DateDiffMicrosecond(start, end) | DATEDIFF(microsecond, @start, @end)
Expand Down Expand Up @@ -182,6 +200,7 @@ stringValue.Contains(value) | @strin
stringValue.EndsWith(value) | @stringValue LIKE N'%' + @value
stringValue.FirstOrDefault() | SUBSTRING(@stringValue, 1, 1) | EF Core 5.0
stringValue.IndexOf(value) | CHARINDEX(@value, @stringValue) - 1
stringValue.IndexOf(value, startIndex) | CHARINDEX(@value, @stringValue, @startIndex) - 1 | EF Core 7.0
stringValue.LastOrDefault() | SUBSTRING(@stringValue, LEN(@stringValue), 1) | EF Core 5.0
stringValue.Length | LEN(@stringValue)
stringValue.Replace(@oldValue, @newValue) | REPLACE(@stringValue, @oldValue, @newValue)
Expand Down
14 changes: 12 additions & 2 deletions entity-framework/core/providers/sql-server/spatial.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ As mentioned in the main [Spatial Data](xref:core/modeling/spatial) documentatio

This table shows which NTS members are translated into which SQL functions. Note that the translations vary depending on whether the column is of type geography or geometry.

.NET | SQL (geography) | SQL (geometry)
----------------------------------------- | ------------------------------------------------------------ | --------------
.NET | SQL (geography) | SQL (geometry) | Added in
----------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | --------
EF.Functions.CurveToLine(geometry) | @geometry.STCurveToLine() | @geometry.STCurveToLine() | EF Core 7.0
geometry.Area | @geometry.STArea() | @geometry.STArea()
geometry.AsBinary() | @geometry.STAsBinary() | @geometry.STAsBinary()
geometry.AsText() | @geometry.AsTextZM() | @geometry.AsTextZM()
Expand Down Expand Up @@ -92,6 +93,15 @@ polygon.ExteriorRing | @polygon.RingN(1)
polygon.GetInteriorRingN(n) | @polygon.RingN(@n + 2) | @polygon.STInteriorRingN(@n + 1)
polygon.NumInteriorRings | @polygon.NumRings() - 1 | @polygon.STNumInteriorRing()

### Aggregate functions

.NET | SQL | Added in
----------------------------------------------------------------- | ----------------------------- | --------
GeometryCombiner.Combine(group.Select(x => x.Property)) | CollectionAggregate(Property) | EF Core 7.0
ConvexHull.Create(group.Select(x => x.Property)) | ConvexHullAggregate(Property) | EF Core 7.0
UnaryUnionOp.Union(group.Select(x => x.Property)) | UnionAggregate(Property) | EF Core 7.0
EnvelopeCombiner.CombineAsGeometry(group.Select(x => x.Property)) | EnvelopeAggregate(Property) | EF Core 7.0

## Additional resources

* [Spatial Data in SQL Server](/sql/relational-databases/spatial/spatial-data-sql-server)
Expand Down
13 changes: 13 additions & 0 deletions entity-framework/core/providers/sqlite/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ uid: core/providers/sqlite/functions

This page shows which .NET members are translated into which SQL functions when using the SQLite provider.

## Aggregate functions

.NET | SQL | Added in
----------------------------------------------------- | ---------------------------------- | --------
group.Average(x => x.Property) | AVG(Property)
group.Count() | COUNT(*)
group.LongCount() | COUNT(*)
group.Max(x => x.Property) | MAX(Property)
group.Min(x => x.Property) | MIN(Property)
group.Sum(x => x.Property) | SUM(Property)
string.Concat(group.Select(x => x.Property)) | group_concat(Property, '') | EF Core 7.0
string.Join(separator, group.Select(x => x.Property)) | group_concat(Property, @separator) | EF Core 7.0

## Binary functions

.NET | SQL | Added in
Expand Down
9 changes: 9 additions & 0 deletions entity-framework/core/providers/sqlite/spatial.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ polygon.ExteriorRing | ExteriorRing(@polygon)
polygon.GetInteriorRingN(n) | InteriorRingN(@polygon, @n + 1)
polygon.NumInteriorRings | NumInteriorRing(@polygon)

### Aggregate functions

.NET | SQL | Added in
----------------------------------------------------------------- | ----------------------------- | --------
GeometryCombiner.Combine(group.Select(x => x.Property)) | Collect(Property) | EF Core 7.0
ConvexHull.Create(group.Select(x => x.Property)) | ConvexHull(Collect(Property)) | EF Core 7.0
UnaryUnionOp.Union(group.Select(x => x.Property)) | GUnion(Property) | EF Core 7.0
EnvelopeCombiner.CombineAsGeometry(group.Select(x => x.Property)) | Extent(Property) | EF Core 7.0

## Additional resources

* [SpatiaLite Homepage](https://www.gaia-gis.it/fossil/libspatialite)
Expand Down
16 changes: 10 additions & 6 deletions entity-framework/core/querying/complex-query-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ ORDER BY [p].[AuthorId]

The aggregate operators EF Core supports are as follows

- Average
- Count
- LongCount
- Max
- Min
- Sum
.NET | SQL
------------------------ | ---
Average(x => x.Property) | AVG(Property)
Count() | COUNT(*)
LongCount() | COUNT(*)
Max(x => x.Property) | MAX(Property)
Min(x => x.Property) | MIN(Property)
Sum(x => x.Property) | SUM(Property)

Additional aggregate operators may be supported. Check your provider docs for more function mappings.

## Left Join

Expand Down

0 comments on commit 280c86b

Please sign in to comment.