diff --git a/entity-framework/core/providers/sql-server/functions.md b/entity-framework/core/providers/sql-server/functions.md index 75ee7143b1..f7dae58129 100644 --- a/entity-framework/core/providers/sql-server/functions.md +++ b/entity-framework/core/providers/sql-server/functions.md @@ -236,7 +236,8 @@ stringValue.TrimStart() | LTRIM( .NET | SQL | Added in ----------------------------------------------------------------- | --------------------------------------------------------- | -------- -EF.Functions.JsonContains(json, searchValue, path?, searchMode?) | JSON_CONTAINS(@json, @searchValue, @path?, @searchMode?) | EF Core 11.0 +EF.Functions.JsonContains(json, searchValue, path?, searchMode?) | JSON_CONTAINS(@json, @searchValue, @path?, @searchMode?) | EF 11.0 +EF.Functions.JsonPathExists(json, path) | JSON_PATH_EXISTS(@json, @path) | EF 11.0 ## Miscellaneous functions diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index cba75a6203..0da6f1a198 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -104,6 +104,30 @@ ORDER BY ( Similarly, `MinByAsync` orders ascending and returns the element with the minimum value for the key selector. +### EF.Functions.JsonPathExists() + +EF Core 11 introduces `EF.Functions.JsonPathExists()`, which checks whether a given JSON path exists in a JSON document. On SQL Server, this translates to the [`JSON_PATH_EXISTS`](/sql/t-sql/functions/json-path-exists-transact-sql) function (available since SQL Server 2022). + +The following query filters blogs to those whose JSON data contains an `OptionalInt` property: + +```csharp +var blogs = await context.Blogs + .Where(b => EF.Functions.JsonPathExists(b.JsonData, "$.OptionalInt")) + .ToListAsync(); +``` + +This generates the following SQL: + +```sql +SELECT [b].[Id], [b].[Name], [b].[JsonData] +FROM [Blogs] AS [b] +WHERE JSON_PATH_EXISTS([b].[JsonData], N'$.OptionalInt') = 1 +``` + +`EF.Functions.JsonPathExists()` accepts a JSON value and a JSON path to check for. It can be used with scalar string properties, complex types, and owned entity types mapped to JSON columns. + +For the full `JSON_PATH_EXISTS` SQL Server documentation, see [`JSON_PATH_EXISTS`](/sql/t-sql/functions/json-path-exists-transact-sql). + ## Cosmos DB