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

Question on Cosmos DB database provider owned object querying null #24087

Open
codemonkeh-dave opened this issue Feb 8, 2021 · 4 comments
Open

Comments

@codemonkeh-dave
Copy link

codemonkeh-dave commented Feb 8, 2021

Question

I am trying to query against owned objects to see if they are null but I get an exception and can't find a work-around to achieving the query (see sample code).

I know I can add .AsEnumerable() but this will make it a client-side query which I don' t want as it will surely bring all records from the database into process to run the query/filter.

If this is clearly documented somewhere I'm sorry for missing it.

If it makes a difference to the answer my production container is used for multiple types and so I use .HasDiscriminator().

Include your code

To demonstrate the issue, I am using the sample found here https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Cosmos and have added the below simple query into sample.cs.

using (var context = new OrderContext())
{
    var ordersWithAnAddress = await context.Orders.Where(o => o.ShippingAddress != null).ToListAsync();
}

Error

System.InvalidOperationException: 'The LINQ expression 'DbSet<Order>()
    .Where(o => EF.Property<StreetAddress>(o, "ShippingAddress") != null)' could not be translated. Additional information: Translation of member 'OrderId' on entity type 'Order.ShippingAddress#StreetAddress' failed. This commonly occurs when the specified member is unmapped.
Translation of member 'OrderPartitionKey' on entity type 'Order.ShippingAddress#StreetAddress' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'

Provider and version information

EF Core version: 5.0.2
Database provider: Microsoft.EntityFrameworkCore.Cosmos (version 5.0.2)
Target framework: This example is .NET 5.0 but the issue also happens in my project in .netcore 3.2
Operating system: Windows 10
IDE: (e.g. Visual Studio 2019 16.8.4)

@smitpatel
Copy link
Contributor

Blocked on #17722

The issue happens since we try to rewrite to entity equality but the property doesn't exist on server side for owned entity. We need to translate it to IS_DEFINED which requires refactoring in cosmos SQL tree.

@smitpatel smitpatel removed this from the 6.0.0 milestone Aug 18, 2021
@ajcvickers ajcvickers added this to the Backlog milestone Aug 20, 2021
@nlpMbordogna
Copy link

I see you guys are punting on this. This is kind of an importing thing, we can't safely query any owned entities without it. Do you have a work around? we are dealing with the IQueryable

@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Nov 10, 2021
@smitpatel smitpatel removed their assignment Nov 19, 2021
@gabolarraguivel
Copy link

Any update on this? Is there any workaround?

@aladd04
Copy link

aladd04 commented Mar 5, 2024

Any chances this gets looked at again, or has anyone come across a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants