我在尝试通过EF6中的LINQ对一些值进行分组和求和时遇到以下错误:
无法创建"System.Char"类型的常量值.在此上下文中仅支持基元类型或枚举类型.
我在StackOverflow上看了六个类似的问题,找不到我的问题.这是查询:
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();
Run Code Online (Sandbox Code Playgroud)
这是我的分组(我是新手)吗?底层EF6模型很好(我可以扩展结果视图_context.HoursProviderCosts并查看数据就好了).
谢谢
编辑:方法签名:
public List<Models.InsuranceCostListItem> InsuranceCostsListItems(DateTime periodStart, string insuranceName) {
Run Code Online (Sandbox Code Playgroud)
15e*_*153 15
尝试使用字符串文字而不是字面文字:
PatientName = g.Key.PatientFirstName + " " + g.Key.PatientLastName.
Run Code Online (Sandbox Code Playgroud)