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) {
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With