CosmosDB-实体框架核心-包含的内容无法翻译

时间:2019-10-29 09:31:33

标签: azure-cosmosdb entity-framework-core-3.0

我尝试使用实体框架核心3.0(Microsoft.EntityFrameworkCore.Cosmos 3.0.0)操作CosmosDB(SQL)。

一切正常,除非我尝试使用ContainsStartWith,...

例如:

var query = _context.Challenges.Where(c => c.Name.Contains( "string"));

EF应该将其转换为以下SQL(在CosmosDB –查询浏览器上完美运行)

SELECT * FROM c WHERE CONTAINS(c.Name, "string")

但是我收到以下错误消息:

The LINQ expression 'Where<Challenge>(\n    source: DbSet<Challenge>, \n    predicate: (c) => c.Name.Contains(\"string\"))' 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.

当然,我不想像下面这样编码,它将在客户端上执行整个包含,只是为了做一个简单的LIKE…

List<Challenge> entities = _context.Challenges.AsEnumerable().Where(c => c.Name.Contains( "string")).ToList();

任何人都有一个评估服务器端“包含”的想法吗?

注意:我使用UseSqlServer而不是UseCosmos(并通过添加所需的[Key]批注并创建SQL服务器)尝试使用完全相同的代码,它的工作原理就像一个魅力。...因此,它绝对是CosmosDB vs EF问题。