Question on Cosmos DB database provider owned object querying null
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)
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.
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
Any update on this? Is there any workaround?
Any chances this gets looked at again, or has anyone come across a workaround?
I have a PR open for this with a possible solution in #37321