C# - LINQ to Entity查询将属性的值附加到一个变量

Ler*_*ica 0 c# linq-to-entities

我有这个问题:

var sole = SoleService.All().Where(c => c.Status != 250)
               .Select(x => new { 
                    ID = x.ID, Code = new {CodeName = x.Code + x.Country}, 
                    Name = x.Name 
               })
               .Distinct()
               .OrderBy(s => s.Code);
Run Code Online (Sandbox Code Playgroud)

像这样它给我一个错误.我想要的是组合CodeCountry喜欢concat字符串,所以我可以使用新的变量作为我的数据源.就像是 -001France

PS

我正在使用并正在运行的是:

var sole = SoleService.All().Where(c => c.Status != 250)
               .Select(x => new { 
                   ID = x.ID, Code = x.Code, Name = x.Name, Country = x.Country })
               .Distinct()
               .OrderBy(s => s.Code);
Run Code Online (Sandbox Code Playgroud)

所以我需要修改这个查询,以便我可以Code +Country用作一个变量.以上是我认为可行的尝试.

cuo*_*gle 5

听起来像:

 var sole = SoleService.All().Where(c => c.Status != 250)
                .AsEnumerable()
                .Select(x => new { 
                                ID = x.ID, 
                                Code = x.Code + x.Country, 
                                Name = x.Name
                                })
                .Distinct()
                .OrderBy(s => s.Code);
Run Code Online (Sandbox Code Playgroud)

你根本不需要内部匿名类型.如果您正在使用EF,+则不支持正弦字符串,请AsEnumerable在执行select之前调用.