我有如下代碼:
public static class IntegrationServiceExtensions
{
public static IQueryable<T> LearningObjectContainerIncludeNestedProperties<T>(this IQueryable< T> query) where T : LearningObjectContainer
{
query.Include(x => x.Bases)
.Include(x => x.LearningObjectives).ThenInclude(x => x.Classifications)
.Include(x => x.Classifications)
.Include(x => x.ContainerPropertyImplementations)。
return查詢。
}
}
//Include不作業。
public async Task<LearningObjectContainer> GetLearningObjectContainer(int id)。
{
var query = _applicationDbContext.LearningObjectContainers.LearningObjectContainerIncludeNestedProperties()。
var learningObjectContainer = await query.FirstOrDefaultAsync(x => x.Id == id);
return learningObjectContainer;
}
//包括作業。
public async Task<LearningObjectContainer> GetLearningObjectContainer(int id)。
{
var query = _applicationDbContext.LearningObjectContainers
.Include(x => x.Bases)
.Include(x => x.LearningObjectives).ThenInclude(x => x.Classifications)
.Include(x => x.Classifications)
.Include(x => x.ContainerPropertyImplementations)。
var learningObjectContainer = await query.FirstOrDefaultAsync(x => x.Id == id);
return learningObjectContainer;
為什么在使用擴展方法時,我不能使用急切的加載?
https://docs.microsoft.com/en-us/ef/core/querying/related-data/eager
我試著用急于加載的方式進行分割查詢,但沒有成功。
public static IQueryable< T> LearningObjectContainerIncludeNestedProperties< T>(this IQueryable<T> query) where T : LearningObjectContainer
{
query.Include(x => x.Bases)
.Include(x => x.LearningObjectives).ThenInclude(x => x.Classifications)
.Include(x => x.Classifications)
.Include(x => x.ContainerPropertyImplementations)
.AsSplitQuery()。
return查詢。
}
https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries
uj5u.com熱心網友回復:
我認為這種方法應該是:
public static IQueryable< T> LearningObjectContainerIncludeNestedProperties< T>(this IQueryable<T> query) where T : LearningObjectContainer
{
query = query.Include(x => x.Bases)
.Include(x => x.LearningObjectives).ThenInclude(x => x.Classifications)
.Include(x => x.Classifications)
.Include(x => x.ContainerPropertyImplementations)。
return查詢。
}
它只是缺少對IQueryable結果的查詢重新賦值/w Include。("query = ")
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/307080.html
標籤:
上一篇:在C#中讓按鈕在5秒后永遠出現








