Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EF7 function translations #4001

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a general conceptual doc section showing how to use aggregate functions in various scenarios, opened #4002.

BTW technically the thing that GroupBy returns is called a "grouping" rather than a group, we may want to align (though I think group is OK too).

For reference, here are the PG translations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically the thing that GroupBy returns is called a "grouping" rather than a group

lol, I had the same internal debate. In the end, I went for the shorter one.

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