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 Where query on owned properties throws a translation exception #26849

Closed
yochail opened this issue Nov 29, 2021 · 7 comments
Closed

Cosmos Where query on owned properties throws a translation exception #26849

yochail opened this issue Nov 29, 2021 · 7 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@yochail
Copy link

yochail commented Nov 29, 2021

Ask a question

I'm in the process of implementing a Cosmos DB access with an entity framework provider,
And every query I'm trying to run on Owned Entity gets a translation error.
I tried many different queries. and I get this error only on owned entities like in the code example.
I think this query type should be possible like in this test:
https://github.com/dotnet/efcore/blob/main/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs

code

The (simplefied) document classes

	public class StructuredTrial
	{
		public string TrialId { get; set; }
		public ICollection<StringWrapper> ConditionCodesList { get; set; }
	}

	public class StringWrapper
	{
		[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
		public string Id { get; set; }
		public string StrValue { get; set; }
	}

Context definition:

modelBuilder.HasDefaultContainer("StructuredTrials");
			modelBuilder.Entity<StructuredTrial>().HasKey(s => s.TrialId);
			modelBuilder.Entity<StructuredTrial>().HasPartitionKey(s => s.TrialId);
			modelBuilder.Entity<StructuredTrial>().OwnsMany(c => c.ConditionCodesList, c =>
			{
				c.HasKey(p => p.Id);
			});

Calling code I tried, with similar error (error provided is for the first one):

var db = new KnowledgeGraphDBContext(_dbOptions);
var studiesQuery = await db.StructuredTrials.AsQueryable()
				                       .Where(s => s.ConditionCodesList.IsDefined()).ToListAsync();
				                       
var studiesQuery = await db.StructuredTrials.AsQueryable()
				                       .Where(s => s.ConditionCodesList.Count() > 0).ToListAsync();	

var studiesQuery = await db.StructuredTrials.AsQueryable()
				                       .Where(s => s.ConditionCodesList.Contains(null)).ToListAsync();				                     

Error Output

System.InvalidOperationException: 'The LINQ expression 'DbSet<StructuredTrialTest>()
    .Where(s => MaterializeCollectionNavigation(
        Navigation: StructuredTrialTest.ConditionCodesList,
        subquery: EF.Property<ICollection<StringWrapperTest>>(s, "ConditionCodesList")
            .AsQueryable()
        .IsDefined())' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'

stack traces

   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& ) in /_/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs:line 105

Include provider and version information

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.Cosmos 5.0.12)
Target framework: (e.g. .NET 3.1)
Operating system:
IDE: (e.g. Visual Studio 2022 17.0.1)

@ajcvickers
Copy link
Member

/cc @smitpatel

@smitpatel
Copy link
Member

IsDefined function is unknown to us.
Others #17957

@ajcvickers
Copy link
Member

@smitpatel IsDefined comes from the Microsoft.Azure.Cosmos.Linq LINQ provider. It's interesting to consider that people may try to use these with the EF Core LINQ provider.

/cc @AndriySvyryd

@yochail
Copy link
Author

yochail commented Nov 29, 2021

@smitpatel it was just an examle, none of the other options there worked, for onstance:
var studiesQuery = await db.StructuredTrials.AsQueryable()
.Where(s => s.ConditionCodesList.Contains(null)).ToListAsync()
i dont need specificlly the IsDefined function, I plan to implement a custum Sql function using Array contains but there seems to be an issue on the owned property access

@ajcvickers
Copy link
Member

@yochail The pattern in general is tracked by issue #17957, as referenced by @smitpatel above. Please vote for that issue if this is something important to you.

@yochail
Copy link
Author

yochail commented Nov 29, 2021

@ajcvickers
Copy link
Member

@yochail Which test do you mean, specifically? Many of those tests are skipped with reference to #17246.

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Dec 7, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants