繁体   English   中英

在一个列上执行trim()时具有多个列的Linq

[英]Linq with multiple columns while doing a trim() on a column

我正在尝试编写一个linq查询,使我可以对要分组的列之一进行修整。

这是我到目前为止的内容,但无法正常工作,我遇到了2个错误:

var statusGroup =
        (from r in cxt.unilists
         group r by new { r.type, r.csname.Trim() } status
         into sg
         select new ClaimListListTotalLinqPresentation
                    {
                         Type = sg.Key.type,
                         Status = sg.Key.csname,
                         ClaimCount = sg.Count(),
                         ClaimTotal = sg.Sum(x => x.claimtotal)
                    })                         
                    .Where(x => x.Type == "HOSP").ToList();

错误:

无效的匿名类型成员声明符。 必须使用成员分配,简单名称或成员访问来声明匿名类型成员。

'AnonymousType#1'不包含'csname'的定义,并且找不到扩展方法'csname'接受类型为'AnonymousType#1'的第一个参数(您是否缺少using指令或程序集引用?)

我正在尝试对r.csname进行修整

new { r.type, r.csname }

是以下简称

new { type = r.type, csname = r.csname }

使用新属性时,使用使用的属性的名称。 但是,当您添加.Trim() ,它不再是对属性的直接使用,因此没有默认名称。 您想要的是:

new { r.type, csname = r.csname.Trim() }

那应该解决两个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM