-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Translate subquery in filter condition #17957
Comments
CosmosDb also supports Exists operator. I could not find it docs (hence it hasn't implemented yet) but query runs correctly. |
@smitpatel you mean there is an undocumented way to achieve the same result using EF als linq? Or what do you mean exactly? |
I meant that it is not in cosmos docs so we did not know that such SQL was valid. Hence it does not work in EF Core yet. |
EXISTS operator is described here:
https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-subquery#exists-expression
In the meantime; is there an alternative way to achieve the same result with EFCore?
|
No work-around. |
Related to #16146 |
@AndriySvyryd @smitpatel are there any other operators that do translate into a subquery (JOIN, SELECT, ...)? |
@NickSevens - We don't have translation of subcollections composition in Cosmos yet. Mainly |
@NickSevens did you ever happen to find a work around for this? I'm in exactly the same position and it doesn't look like native support has been added yet. I could be missing something though. @smitpatel is this something you have on the roadmap? |
Please see this too, it should be the same error |
@Aford73 that's true, though note that EF Core does allow you to compose LINQ operators over raw SQL - not sure exactly what it would look like with OData, but I'm assuming it's possible. In any case, we're not currently planning on working on this for 7.0 (the issue is in the Backlog milestone), so it may be a good idea to look at workarounds. |
Thanks vey much for the response @roji we'll take a look at the LINQ possibilities If anyone else has gone down this route it would be interesting to hear your findings? |
I am running into the same issue querying array fields of any type, in EF 6.0. |
Hi Guys, We are also facing same kind of issue. await _dbContext.MyEntities Do we have any solutions for this? |
@roji @NickSevens I tried the FromRawSql approach with an EXISTS clause, however the data I get back seems to be nested inside a "c: ..." tag, instead of returning the array at the root. I think this may be due to EFCore wrapping the SQL in a "SELECT c FROM (...) c", which I cannot seem to change to "SELECT VALUE c FROM ...". More detail here: https://stackoverflow.com/questions/73386712/how-do-i-access-the-value-using-cosmosqueryableextensions The result is that I get no data back, however when I copy the EFCore translated query from the log into Data Explorer and modify it to "SELECT VALUE c.." then it works as expected. UPDATE |
Hello! Is this planned to be fixed with EF Core 7.0? |
This issue is in the Backlog milestone. This means that it is not going to happen for the 7.0 release. We will re-assess the backlog following the 7.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. |
I think this is one of the most important things to fix, because there is no way of querying nested objects aside of using FromSqlQuery. Forget about using LINQKit or another library that makes querying easier. I will move from using EF Core to Azure Cosmos DB Repository until this critical feature is implemented. |
I’ve found that using the CosmosClient’s Linq provider is able to translate queries like this. EF Core is a great piece of tech, but it still needs some time with Cosmos in order to generate the correct expression trees. My recommendation is to switch to using the CosmosClient Linq provider (which is also recommended by the devs who created the cosmos client library) over EF Core for the time being. |
Hi,
Using EF 7.0 wit a LINQ query expression it get translated into this;
When the query is executed I get this error:
Do you have any solution for this besides using the the CosmosClient? |
@hasmMarques try using (await DbSet<FirmwareInformation>()
.Where(x => x.DeletedTimestamp == null && x.ApplicableProducts)
.Where(inner => inner == "test0")
.CountAsync()) > 0; |
@wbuck thanks for your reply.
|
Hi all, could you please inform me if the issue that I detailed here has been resolved in EF8 or EF9, or if a resolution is still pending. |
I can confirm that the query types listed on this issue should be fully working on EF 9.0 (this is a specific case of querying over nested collections, #16926, #25364). If memory serves, preview.7 - to be released in the next few days - should already work, so once that's released can you please test with it and report back on this issue? |
Hi Roji, These are excellent news. |
Consider this CosmosDb document structure:
When querying data I would like to perform a query which filters on AuthorizedUsers properties. E.g.:
However, this results in a query translation error:
Question: is this something that is or should be possible to achieve? The same query can be executed on CosmosDB SQL syntax, like this:
The text was updated successfully, but these errors were encountered: