C# Linq Entity Conversion Error on Nonexistent Value?
- by Ryan
While trying to query some data using the Linq Entity Framework I'm receiving the following exception:
{"Conversion failed when converting the varchar value '3208,7' to data type int."}
The thing that is confusing is that this value does not even exist in the view I am querying from. It does exist in the table the view is based on, however. The query I'm running is the following:
return context.vb_audit_department
.Where(x => x.department_id == department_id && x.version_id == version_id)
.GroupBy(x => new { x.action_date, x.change_type, x.user_ntid, x.label })
.Select(x => new
{
action_date = x.Key.action_date,
change_type = x.Key.change_type,
user_ntid = x.Key.user_ntid,
label = x.Key.label,
count = x.Count(),
items = x
})
.OrderByDescending(x => x.action_date)
.Skip(startRowIndex)
.Take(maximumRows)
.ToList();
Can somebody explain why LINQ queries the underlying table instead of the actual view, and if there is any way around this behavior?