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
Comparing against a list of sub-object in a document is not working in cosmos DB. I have the following classes and db context-
public class Company {
public string id { get; set; }
public string name { get; set; }
public List<StockIndex> Indexes { get; set; } = new List<StockIndex>();
}
public class StockIndex
{
public string? Name { get; set; }
public bool IsPrimary { get; set; } = false;
}
public class CompaniesContext : DbContext
{
public DbSet<Company> Companies { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseCosmos(
"https://test-data.documents.azure.com:443",
"xxxxxxxxxxxxxxxxxxxxxxxxx",
databaseName: "dbname").
EnableDetailedErrors().
EnableSensitiveDataLogging();
}
Following query fails to execute-
using var companiesContext = new CompaniesContext();
try
{
var innerDocument = new StockIndex() { Name = "DJIA" };
var result = companiesContext.Companies.Where(c=>c.Indexes.Contains(innerDocument)).AsNoTracking();
foreach (var c in result)
{
Console.WriteLine(c);
}
}
catch (Exception ex)
{
}
Error message
The LINQ expression 'DbSet()
.Where(c => EF.Property<List>(c, "Indexes")
.AsQueryable()
.Any(p => p == __innerDocument_0))' 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.g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& ) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 108
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 491
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression) in C:\JF\efcore\src\EFCore.Cosmos\Query\Internal\CosmosQueryableMethodTranslatingExpressionVisitor.cs:line 140
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 121
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression) in C:\JF\efcore\src\EFCore.Cosmos\Query\Internal\CosmosQueryableMethodTranslatingExpressionVisitor.cs:line 140
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) in C:\JF\efcore\src\EFCore\Query\QueryCompilationContext.cs:line 189
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) in C:\JF\efcore\src\EFCore\Storage\Database.cs:line 76
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 111
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_01.<Execute>b__0() in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 95 at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) in C:\JF\efcore\src\EFCore\Query\Internal\CompiledQueryCache.cs:line 74
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 91
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) in C:\JF\efcore\src\EFCore\Query\Internal\EntityQueryProvider.cs:line 78
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable1.GetEnumerator() in C:\JF\efcore\src\EFCore\Query\Internal\EntityQueryable.cs:line 90
at Program.
$(String[] args) in C:\JF\POCs\POCs\New folder\CosmosEntityFrameworkPOC\Program.cs:line 33
Include provider and version information
EF Core version: 6
Database provider: Cosmos
Target framework: .net 6
Operating system: Windows 11
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered:
Comparing against a list of sub-object in a document is not working in cosmos DB. I have the following classes and db context-
Following query fails to execute-
Error message
The LINQ expression 'DbSet()
.Where(c => EF.Property<List>(c, "Indexes")
.AsQueryable()
.Any(p => p == __innerDocument_0))' 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
$(String[] args) in C:\JF\POCs\POCs\New folder\CosmosEntityFrameworkPOC\Program.cs:line 33at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& ) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 108
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 491
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression) in C:\JF\efcore\src\EFCore.Cosmos\Query\Internal\CosmosQueryableMethodTranslatingExpressionVisitor.cs:line 140
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in C:\JF\efcore\src\EFCore\Query\QueryableMethodTranslatingExpressionVisitor.cs:line 121
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression) in C:\JF\efcore\src\EFCore.Cosmos\Query\Internal\CosmosQueryableMethodTranslatingExpressionVisitor.cs:line 140
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) in C:\JF\efcore\src\EFCore\Query\QueryCompilationContext.cs:line 189
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) in C:\JF\efcore\src\EFCore\Storage\Database.cs:line 76
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 111
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0
1.<Execute>b__0() in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 95 at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func
1 compiler) in C:\JF\efcore\src\EFCore\Query\Internal\CompiledQueryCache.cs:line 74at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) in C:\JF\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 91
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) in C:\JF\efcore\src\EFCore\Query\Internal\EntityQueryProvider.cs:line 78
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable
1.GetEnumerator() in C:\JF\efcore\src\EFCore\Query\Internal\EntityQueryable
.cs:line 90at Program.
Include provider and version information
EF Core version: 6
Database provider: Cosmos
Target framework: .net 6
Operating system: Windows 11
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered: