I have entity:
class Contract
{
public TenantProfile TenantProfile { get; set; }
public ContractStatus Status { get; set; }
}
Service ( override GetAsync(Id)
):
var contractWithDetails = (await Repository.WithDetailsAsync(x => x.Status)).FirstOrDefault(x => x.Id == id);
But property TenantProfile
- null, because I can't execute WithDetailsAsync
for IQueryable
. How to solve my problem and execute more then 2 WithDetailsAsync
?
It is suggested to create an extension method for each aggregate root with sub collections :
public static IQueryable<Contract> IncludeDetails(
this IQueryable<Contract> queryable,
bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.TenantProfile)
.Include(x => x.ContractStatus);
}
Now you can override WithDetailsAsync
:
public override async Task<IQueryable<Contract>> WithDetailsAsync()
{
// Uses the extension method defined above
return (await GetQueryableAsync()).IncludeDetails();
}
Now your WithDetailsAsync
method includes both of them.
See more on ABP Entity Framework Core Integration Best Practices docs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.