Skip to content

Instantly share code, notes, and snippets.

@Grinderofl
Created April 5, 2019 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grinderofl/d3d2891ca5e01d8e65d4d2adaf7e2f30 to your computer and use it in GitHub Desktop.
Save Grinderofl/d3d2891ca5e01d8e65d4d2adaf7e2f30 to your computer and use it in GitHub Desktop.
Projection Example
public static readonly Expression<Func<TicketAggregate, Ticket>> Projection =
x => new Ticket()
{
ReportedBy = x.ReportedBy != null ? x.ReportedBy.Name : "",
Client = x.Client != null ? x.Client.Name : "",
Number = x.Number,
Summary = x.Summary,
Priority = x.Priority != null ? x.Priority.Name : "",
Space = x.Space != null ? x.Space.Slug : "",
Project = x.Project != null ? x.Project.Name : "",
Status = x.Status != null ? x.Status.Name : "",
IncomeCategory = x.IncomeCategory != null ? x.IncomeCategory.Name : "",
AccountManager = x.Project != null && x.Project.AccountManager != null ? x.Project.AccountManager.Name : "",
AssignedTo = x.AssignedTo != null ? x.AssignedTo.Name : "",
Milestone = x.Milestone != null ? x.Milestone.Name : "",
PreferredResource = x.PreferredResource != null ? x.PreferredResource.Name : "",
StartDay = x.StartDay != null ? x.StartDay.Name : "",
TicketId = x.Number,
Description = x.Description,
DueDate = x.DueDate,
HoursRequested = x.TimeRequestedInHours,
HoursWorked = x.TimeWorkedInHours,
MoreTimeRequiredInNextMilestone = x.MoreTimeRequiredInNextMilestone,
Rolling = x.Rolling,
MilestoneId = x.MilestoneId,
MilestoneStartDate = x.Milestone != null ? x.Milestone.StartDate : DateTimeOffset.UtcNow
};
public async Task<Model> Handle(Request request, CancellationToken cancellationToken)
{
var query = context.Tickets.AsNoTracking().AsQueryable();
query = FilterQuery(query, request);
var total = await query.CountAsync(cancellationToken);
query = OrderQuery(query, request);
query = PageQuery(query, request);
var projection = query.Select(Ticket.Projection);
var list = await projection.ToListAsync(cancellationToken);
return new Model(list, total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment