Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create a constant value of type 'System.Char'

Tags:

c#

linq

I'm getting the following error trying to group and sum some values via LINQ in EF6:

Unable to create a constant value of type 'System.Char'. Only primitive types or enumeration types are supported in this context.

I've looked at half a dozen similar questions on StackOverflow and can't find my issue. Here's the query:

var q = from c in _context.HoursProviderCosts
        where c.PatientInsuranceCompanyName == insuranceName
            && c.HoursDate >= startDate
            && c.HoursDate <= endDate
        group c by new { c.ID, c.PatientFirstName, c.PatientLastName } into g
        select new Models.InsuranceCostListItem
        {
            PatientID = g.Key.ID,
            PatientName = g.Key.PatientFirstName + ' ' + g.Key.PatientLastName,
            Total = g.Sum(x => x.ProviderRate)
        };

return q.ToList();

Is it something in my grouping (which I'm new to)? The underlying EF6 model is fine (I can expand the results view of _context.HoursProviderCosts and look at the data just fine).

Thanks

Edit: method signature:

public List<Models.InsuranceCostListItem> InsuranceCostsListItems(DateTime periodStart, string insuranceName) {
like image 682
jleach Avatar asked Sep 22 '16 15:09

jleach


1 Answers

Your space is single-quoted, so it's a character literal. EF6 doesn't know how to translate that to SQL. If you use double quotes, the space is a string, and EF6 knows what to do.

PatientName = g.Key.PatientFirstName + " " + g.Key.PatientLastName.
like image 116
15ee8f99-57ff-4f92-890c-b56153 Avatar answered Nov 16 '22 08:11

15ee8f99-57ff-4f92-890c-b56153