使用Abp封装的CrudAppService中的 GetAsync 获取聚合根中Details为null。
查看源码(EfCoreRepository.cs)后发现仓储方法是有WithDetailsAsync和WithDetails方法
[Obsolete("Use WithDetailsAsync")] public override IQueryable<TEntity> WithDetails() { if (AbpEntityOptions.DefaultWithDetailsFunc == null) { return base.WithDetails(); } return AbpEntityOptions.DefaultWithDetailsFunc(GetQueryable()); } public override async Task<IQueryable<TEntity>> WithDetailsAsync() { if (AbpEntityOptions.DefaultWithDetailsFunc == null) { return await base.WithDetailsAsync(); } return AbpEntityOptions.DefaultWithDetailsFunc(await GetQueryableAsync()); }
从源码中看出有个配置项 AbpEntityOptions.DefaultWithDetailsFunc
配置方法:
EntityFrameworkCoreModule.cs
public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAbpDbContext<ERPDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true); }); Configure<AbpDbContextOptions>(options => { options.UseSqlServer(); }); Configure<AbpEntityOptions>(options => { options.Entity<DemandOrder>(DemandOrderOptions => { DemandOrderOptions.DefaultWithDetailsFunc = query => query.Include(o => o.Items); }); }); }