jdl134679 jdl134679 - 6 months ago 30
C# Question

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

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
and look at the data just fine).


Edit: method signature:

public List<Models.InsuranceCostListItem> InsuranceCostsListItems(DateTime periodStart, string insuranceName) {


Try using a string literal instead of a char literal:

PatientName = g.Key.PatientFirstName + " " + g.Key.PatientLastName