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

Cosmos: Add support for IS_DEFINED() to EF.Functions #17722

Closed
divega opened this issue Sep 9, 2019 · 8 comments
Closed

Cosmos: Add support for IS_DEFINED() to EF.Functions #17722

divega opened this issue Sep 9, 2019 · 8 comments
Assignees
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 punted-for-8.0 Originally planned for the EF Core 8.0 (EF8) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@divega
Copy link
Contributor

divega commented Sep 9, 2019

The full context is explained in #13131, but I decided to create a new issue to gather more targeted customer feedback on this.

The short version is that in a schema-less database like Cosmos DB it is valid for each document in a container to contain completely different set of properties. In an object mapping situation this translates into some of the mapped properties being absent. Cosmos DB provides a function IS_DEFINED() that can be used in queries to test for this situation. Note also that a property not being defined is different (albeit one can argue only slightly) from the value being null.

The Cosmos DB provider could define an extension method in EF.Functions that could be used, for example, like this:

var itemsMissingData = context.Items.Where(i => !EF.Functions.IsDefined(i.Data));
@divega divega added this to the Backlog milestone Sep 9, 2019
@divega divega removed this from the Backlog milestone Sep 9, 2019
@divega
Copy link
Contributor Author

divega commented Sep 9, 2019

It seems that Cosmos DB is still filtering out documents where a property is undefined if you ORDER BY that property. This makes providing access to the IS_DEFINED() function from LINQ queries more important. That way, you can use it like this:

var orderedItems = context.Items.OrderBy(i => i.Data);
var itemsMissingData = context.Items.Where(i => !EF.Functions.IsDefined(i.Data));
orderedItems.AddRange(itemsMissingData);

@smitpatel
Copy link
Contributor

Also consider Coalesce operator ?? which is used to coalesce based on present keys.

@prachita-mane
Copy link

Do we have a timeline on when this will be implemented?

@AndriySvyryd
Copy link
Member

@prachita-mane It's in the backlog meaning we don't plan on working on it in the upcoming releases. However we are open to well-written external PRs.

@clintsinger
Copy link

Is there an alternative to this? For example I am trying to check if a nested property is null and am getting an exception about the query not being able to be translated. My query looks like the following where .Provider is a complex type. I only want to return types where there isn't a Provider field set.

.Where(p => p.Provider == null)

This throws the following exception:

DbSet
.Where(u => EF.Property<Nullable>(EF.Property(u, "Provider"), "UserId") == null)' could not be translated.

Are we dealing with the same/similar thing here?

I would have expected the translation for CosmosDB to be as simple as

WHERE c["Provider"] == null

@AndriySvyryd
Copy link
Member

AndriySvyryd commented May 5, 2022

Note to implementer, add these test cases:

  • IsDefined in a Where call
  • IsDefined in a Select call that creates an anonymous type
  • IsDefined on a shadow property (Person.__id)
  • IsDefined on a derived property (Bird.IsFlightless in InheritanceQueryCosmosTest)
  • IsDefined on an embedded scalar property (OwnedPerson.PersonAddress.Country.Name in OwnedQueryCosmosTest)
  • IsDefined on an embedded scalar collection
  • IsDefined on an embedded reference navigation (OwnedPerson.PersonAddress in OwnedQueryCosmosTest, can throw)
  • IsDefined on an embedded collection navigation (OwnedPerson.Orders in OwnedQueryCosmosTest, can throw)
  • IsDefined on a non-embedded navigation (Person.Orders, should throw)
  • IsDefined on a non-existing property (Person.NonExisting, should throw)
  • IsDefined on a non-mapped property (Person.__jObject, should throw)

@AndriySvyryd AndriySvyryd modified the milestones: Backlog, 8.0.0 Jun 28, 2023
@ajcvickers ajcvickers added the punted-for-8.0 Originally planned for the EF Core 8.0 (EF8) release, but moved out due to resource constraints. label Jun 28, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0, Backlog Jun 29, 2023
@ajcvickers ajcvickers self-assigned this May 8, 2024
@ajcvickers ajcvickers modified the milestones: Backlog, 9.0.0 May 8, 2024
@roji
Copy link
Member

roji commented Jun 4, 2024

Note also #33904, which is about adding support for the undefined coalescing operator (??).

@roji roji assigned roji, ajcvickers and maumar and unassigned ajcvickers, maumar and roji Jun 8, 2024
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 8, 2024
@roji
Copy link
Member

roji commented Jun 8, 2024

Poaching as I'm in the area with #33904.

roji added a commit to roji/efcore that referenced this issue Jun 8, 2024
roji added a commit to roji/efcore that referenced this issue Jun 8, 2024
roji added a commit to roji/efcore that referenced this issue Jun 11, 2024
@roji roji closed this as completed in 22aec2c Jun 11, 2024
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview6 Jun 21, 2024
@roji roji modified the milestones: 9.0.0-preview6, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 punted-for-8.0 Originally planned for the EF Core 8.0 (EF8) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants