Is it possible to retrieve list of IDs of related records using Ardalis Specification?
For example, Project table has ProjectId, ProjectName, BuildingId columns. Building table has BuildingId and BuildingName columns. I'd like to retrieve the Project record by ProjectId and include related Building Ids. Project to Building is 1 to many.
public sealed class ProjectByProjectIdSpecification : Specification<ProjectEntity>
{
public ProjectByProjectIdSpecification(long id)
{
Query
.AsNoTracking()
.Include(x => x.Buildings) //here I dont want the entire building objects - just the ids
.Where(x => x.Id == id);
}
}
You can use
Select()
for your advantage.Make sure your
ProjectEntity
class has following properties.This way you can retrieve the data you want and it should retrieve only the necessary information, including the BuildingIds.