![](/img/trans.png)
[英]In entity framework 6 SelectMany to Join option for query throwing error The source IQueryable doesn't implement IDbAsyncEnumerable<MyModel>
[英]SelectMany doesn't work on cosmosDb for child properties?
當我嘗試在針對 cosmosdb 構建的可查詢對象上使用 selectMany 時,我總是遇到異常:
LINQ 表達式 'DbSet .Where(t => t.Id == __timelineId_0) .SelectMany( source: 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 庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.