You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a query that seems to be pretty basic. I'm using Core3.1 on top of CosmosDb. I simply want to query a list of orders that have order details, but I'm getting this error:
.Where(b => EF.Property>(b, "OrderDetails") .Any())' could not be translated. Either rewrite the query in a form that can be translated or switch to client evaluation.
Client evaluation isn't an option
Consider this contrived example:
publicclassOrder{publicList<OrderDetail>OrderDetails{get;set;}}publicclassOrderDetail{}// Db ContextmodelBuilder.Entity<Order>().OwnsMany(x =>x.OrderDetails);// The querycontext.Orders.Where( order =>order.OrderDetails.Any());
Reacted by Maksim Lunochkin, Iarly Lana Lins, Roman Marusyk, Rafael Botelho, Josh Hulbert, Aamir Mulla, Umair Butt, Alexssandro Aquino, Boris Sotsky, Fredrik Blixth and 1 more
It is pretty clear fact that EF Core 3.1 does not support that hence you got an exception. If we want to make it working in future version of EF Core then we need a way to represent that in SQL. I don't think discussing about other databases and their capabilities answer that question.
Reacted by Koen
Reacted by Iarly Lana Lins, Roman Marusyk, Umair Butt, Alexssandro Aquino, Boris Sotsky and Kurtis Welch
It's also pretty clear what I'm trying to accomplish. Instead of passive aggressive, you could have offered a workaround, or a simple, I'm sorry, we don't support querying objects that are owned. The mongodb comment was quite valid considering that you can talk mongo protocol to CosmosDb. I would be using it, but that would mean losing EFCore.
Reacted by Roman Marusyk, Alexssandro Aquino and Octarines
There is no work-around else I would have offered you one. While CosmosDb internally use same engine for Azure SQL and mongodb, the protocol to talk to each API is different. Just because CosmosDb mongodb API can do something does not necessarily mean there is SQL equivalent.
Reacted by Iarly Lana Lins, Roman Marusyk, Umair Butt, Alexssandro Aquino and Mikkel Emil Hansen
InvalidOperationException: The LINQ expression 'DbSet<ArticleEntity>()
.Where(a => EF.Property<ICollection<ArticleTagEntity>>(a, "Tags")
.AsQueryable()
.Any(o => o.TagId == 9c60ad92-bd94-4e78-9ece-3a583e7a1004))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Also when we do this in LINQ code like below it gives the same error:
Activity
smitpatel commentedon Mar 27, 2020
Can you provide us what would be expected SQL server side to get the same results?
darthg8r commentedon Mar 28, 2020
If this were on SQL server instead of Cosmos, you could use this to get the orders that have OrderDetails
select * from Orders
where id in (
select distinct OrderId from OrderDetails
)
Or
Select * from Orders
inner join OrderDetails on Order.Id = OrderDetails.OrderId
smitpatel commentedon Mar 28, 2020
We are talking about Cosmos translation. Cosmos does not run all the SQL, SqlServer can run.
darthg8r commentedon Mar 28, 2020
It's surely possible to get a list of objects that has more than one owned object. Right? Seems pretty basic. Mongo can do it.
smitpatel commentedon Mar 28, 2020
Surely you can use mongo then.
darthg8r commentedon Mar 28, 2020
Is that your passive aggressive way of saying no, it doesn't support that?
smitpatel commentedon Mar 28, 2020
It is pretty clear fact that EF Core 3.1 does not support that hence you got an exception. If we want to make it working in future version of EF Core then we need a way to represent that in SQL. I don't think discussing about other databases and their capabilities answer that question.
darthg8r commentedon Mar 28, 2020
It's also pretty clear what I'm trying to accomplish. Instead of passive aggressive, you could have offered a workaround, or a simple, I'm sorry, we don't support querying objects that are owned. The mongodb comment was quite valid considering that you can talk mongo protocol to CosmosDb. I would be using it, but that would mean losing EFCore.
smitpatel commentedon Mar 28, 2020
There is no work-around else I would have offered you one. While CosmosDb internally use same engine for Azure SQL and mongodb, the protocol to talk to each API is different. Just because CosmosDb mongodb API can do something does not necessarily mean there is SQL equivalent.
darthg8r commentedon Mar 28, 2020
Ok, here's working SQL
select * from c where ARRAY_LENGTH(c.OrderDetails) > 0
benabdalla-oussama commentedon Jun 9, 2020
Hello everyone,
I've got the same issue.
These are my classes.
and this is my DB context,
we are using the above classes and we use Odata URL for retrieving, see example below:
https://localhost:44326/odata/articles?$filter=Tags/any(c: c/TagId eq 9c60ad92-bd94-4e78-9ece-3a583e7a1004)
this creates the error below:
Also when we do this in LINQ code like below it gives the same error:
This is a test situation, I think this should be supported.
Thank you in advance,
Oussama.
15 remaining items
Cosmos querying over arrays of structural type
Cosmos querying over arrays of structural type
Cosmos querying over arrays of structural type
Cosmos querying over arrays of structural type
Cosmos querying over arrays of structural type (dotnet#33998)