C# Linq Entity Conversion Error on Nonexistent Value?

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-04-09T19:22:23Z Indexed on 2010/04/09 19:43 UTC
Read the original article Hit count: 392

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ