gpt4 book ai didi

c# - 无法创建类型为 'System.Char' 的常量值

转载 作者:太空狗 更新时间:2023-10-29 19:59:25 26 4
gpt4 key购买 nike

我在尝试通过 EF6 中的 LINQ 对一些值进行分组和求和时遇到以下错误:

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

我在 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();

它在我的分组中(我是新手)吗?底层 EF6 模型很好(我可以展开 _context.HoursProviderCosts 的结果 View 并查看数据就好了)。

谢谢

编辑:方法签名:

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

最佳答案

你的空间是单引号的,所以它是一个字 rune 字。 EF6 doesn't know how to translate that to SQL .如果使用双引号,空格就是一个字符串,EF6 知道该怎么做。

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

关于c# - 无法创建类型为 'System.Char' 的常量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39642772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com