So this happens when I try to get data from my Web Api:
ExceptionMessage:
Only parameterless constructors and initializers are supported in LINQ to Entities.
This is my service:
public async Task<ICollection<TicketDto>> GetAllUnansweredTicketsAsync()
{
return await _context.Tickets.Include(m => m.Message)
.Include(u=>u.User)
.OrderByDescending(d=>d.Message.Date)
.Select(t => new TicketDto(t)).ToListAsync();
This is how my DTO looks like:
public class TicketDto
{
public int ID { get; set; }
public string Username { get; set; }
public string Issue { get; set; }
public DateTime Date { get; set; }
public TicketDto(Ticket ticket)
{
ID = ticket.ID;
Username = ticket.User.UserName;
Issue = ticket.Message.Title;
Date = ticket.Message.Date;
}
}
Can someone explain me how to fix this?