Hi,
Base on Entity/Application Services Best Practices,My Question is how to fill Detailed DTO Reference Properties (Ex: IssueWithDetailsDto.MileStone ) efficiently.
My Solution is to build Detailed DTO By LINQ (Base XXXRepository.AsQueryable()) inside the application service methods,is this accord with best practices?

https://docs.abp.io/en/abp/latest/Best-Practices/Entities
https://docs.abp.io/en/abp/latest/Best-Practices/Application-Services
Use object mapping in application services.
@maliming the aggregate roots reference other aggregate roots by Id,aggregate roots just have reference property just like MilestoneId,my question is how to fill dto reference properties Milestone efficiently?
We made a module to help load related DTO from other aggregate, but it is still improving.
@maliming @gdlcf88
In both cases, the navigation properties are populated by foreach postDtos/orderDtos.
Is there an more efficient way to fill dto reference properties?
In my usage scenario, I need to get a big collection just like orders, foreach Dtos is inefficient.
I don't know of other better solutions at the moment.
@jortygu You can override your repository's WithDetails method or new methods for specific includes.
Something like;
public override IQueryable<MyEntity> WithDetails()
{
return GetQueryable().Include("MyEntity.SubCollection.NavEntity");
}
Or to get it better, you can write an extension about it. Like;
public static IQueryable<MyEntity> IncludeMySpecificDetails(this IQueryable<MyEntity> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.MyFirstCollection)
.Include(x => x.MySecondCollection);
}
and call it in repo as;
public override IQueryable<MyEntity> WithDetails()
{
return GetQueryable().IncludeMySpecificDetails();
}
Edit: Just noticed that your issue is about DDD bounded-contexts, not framework-wise technical.
Still keeping the comment for others that may help to.
So your both Issue and Milestone are AggregateRoots?
@gterdem
thanks for your reply.
yes,there are both AggregateRoots,that's the source of this question.
I just want to find a high-efficiency way to populate DTO reference properties and accord with DDD patterns & best practices.
In DDD principles, this scenario does not happen. Because in the case you need return Milestone inside each Issue, you must create a new simple milestone DTO (and normaly a new entity that is not aggregateroot), only with properties that is need for this Use Case.
This is very important principle in DDD (Entities/DTOs by use case), because your actually entity Milestone that is a Aggregateroot as more properties and behaviors, like for example a list of Issues, conditions to be released, etc..
And normally with the evolution of the application you will add more and more properties/behaviors, and because of that it is wrong to try to reuse entities/dto's for different use cases.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
In DDD principles, this scenario does not happen. Because in the case you need return Milestone inside each Issue, you must create a new simple milestone DTO (and normaly a new entity that is not aggregateroot), only with properties that is need for this Use Case.
This is very important principle in DDD (Entities/DTOs by use case), because your actually entity Milestone that is a Aggregateroot as more properties and behaviors, like for example a list of Issues, conditions to be released, etc..
And normally with the evolution of the application you will add more and more properties/behaviors, and because of that it is wrong to try to reuse entities/dto's for different use cases.