Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'where Convert([p].Status, Enum).GetDisplayName().Contains(__searchBy_8)' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'where Convert([p].Status, Enum).GetDisplayName().Contains(__searchBy_8)' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
I am saving the value of Statusstatus enum to the database table ComplaintsComplaints
I have to apply filtering on a querryquery against the search Stringstring along with some other filtering and iI am trying to do this in following way
// Apply Relevant SearchModel filters first
var query = context.Complaints
var query = context.Complaints .Include(s => s.Messages)
.ThenInclude(p => p.User).AsQueryable();
if (dtParams.StartDate != null && dtParams.EndDate != null)
{
query = query.Where(s => s.CreatedAt >= dtParams.StartDate.Value.Date &&
s.CreatedAt <= dtParams.EndDate.Value.Date);
}
string searchBy = dtParams.Search?.Value;
if (!string.IsNullOrEmpty(searchBy))
{
query = query.Where(r => r.ComplaintNo.Contains(searchBy) ||
r.CreatorUsername.Contains(searchBy) ||
( r.CreatedAt != null && r.CreatedAt.ToString().Contains(searchBy) ) ||
(r.Status.GetDisplayName().Contains(searchBy)) ||
r.Messages.Any(p => p.StatusDescription.Contains(searchBy))
);
}
// Convert the Db context to Custom ViewModel which will then be rendered on to a DataTable
var dtQuery = query.SelectMany(x => x.Messages, (complaint, message) => new { complaint, message })
.Select(p => new ListTableViewModel
{
ComplaintNo = $"<a href=\"{Url.Action("GetLabels", new { orderNo = p.complaint.ComplaintNo })}\" target=\"_blank\"> {p.complaint.ComplaintNo}</a>",
Tracking = GenerateTrackingUrl(p.complaint),
Creator = p.complaint.CreatorUsername,
CreatedAt = p.complaint.CreatedAt.ToString("dd/MM/yy"),
Status = $"<span class=\"badge label-{p.complaint.Status}\">{p.complaint.Status.GetDisplayName()}</span>",
Info = p.message.StatusDescription
}).ToList();
Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning:
The LINQ expression 'where Convert([p].Status, Enum).GetDisplayName().Contains(__searchBy_8)' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID
'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning:
The LINQ expression 'where Convert([p].Status, Enum).GetDisplayName().Contains(__searchBy_8)' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
The line causing this exception is where iI am comparing the search text with value of enum