.net-core - SelectMany 不适用于 cosmosDb 的子属性?
问题描述
当我尝试在针对 cosmosdb 构建的可查询对象上使用 selectMany 时,我总是遇到异常:
LINQ 表达式 'DbSet .Where(t => t.Id == __timelineId_0) .SelectMany( 来源: t => EF.Property>(t, "GraduationEvents") .AsQueryable(), collectionSelector: (t, c) = > new TransparentIdentifier(Outer = t, Inner = c))' 无法翻译。以可翻译的形式重写查询,或通过插入对 AsEnumerable()、AsAsyncEnumerable()、ToList() 或 ToListAsync() 的调用显式切换到客户端评估。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2101038。
查询无关紧要,总是在我使用 selectMany 时出现此错误。
示例查询:
await _dbContext.Timelines.Where(x => x.Id == timelineId).Select(x => x.GraduationEvents).SelectMany(x => x).ToListAsync();
我的实体配置:
public void Configure(EntityTypeBuilder<Timeline> builder)
{
builder.HasKey(x => x.Id);
builder.HasAlternateKey(x => x.Id);
builder.OwnsMany(x => x.GraduationEvents, x => x.OwnsMany(graduationEvent => graduationEvent.Subjects));
}
我也尝试使用本机 cosmosClient,但是当我使用普通 sql 查询基础时,我得到空对象(全为空)。任何想法我做错了什么?
Sajid - 我尝试了你的解决方案,但例外仍然相同
解决方案
尝试通过 List 属性 (GraduationEvents) 直接调用 .SelectMany()。
然后我通常调用 AsDocumentQuery() 生成对 CosmosDB 的查询,然后执行该查询以检索结果。
一些伪 c# 来澄清这一点:
var query = this.documentClient.CreateDocumentQuery(uri, options)
.SelectMany(x => x.GraduationEvents).AsDocumentQuery();
List<T> results = new List<T>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync());
}
编辑:此方法使用本机 Azure DocumentClient 库。
推荐阅读
- vba - 如何使用 VBA 代码从 word 文档中提取与目录关联的数据
- java - 为什么我的 Println Statements 会一次全部打印出来?
- ios - 如何从 CustomCell 重置 tableview 中的所有开关
- android - linux下为android构建openh264
- apache-spark - Spark Streaming - 将 json 格式的消息传输到 DataFrame
- powerbi - 无需先重新启动即可安装最新的 Power BI Desktop
- oauth-2.0 - LinkedIn OAuth2 授权码为空
- facebook - Facebook 业务经理使用 Page API
- java - 从 docker 容器内部连接到 Cassandra
- python - 如何组合两个元组列表来创建嵌套字典?