我有以下查询
from c in Customers
where c.salary == "2000"
select new
{
c.Id,
c.Name,
c.Salary
}
输出
ID名称薪水
Id-9395 Ralph 2000
Id-14591 Ramesh
Id-7958 Rakesh
Id-15784 Ram
所有人的工资相同 我想让它显示所有id。输出必须如下所示。
ID名称薪水
Id-9395 Ralph 2000
Id-14591 Ramesh 2000
Id-7958 Rakesh 2000
Id-15784 Ram 2000
我该怎么做?
答案 0 :(得分:0)
看起来你遇到了更深层次的问题,但你可以这样做:
from c in new Customers
let sal = "2000"
where c.Salary == sal
select new
{
c.Id,
c.Name,
sal
};
答案 1 :(得分:0)
试试这个,虽然它与您已有的查询没有区别:
var customers = Customers.Select(x=> new {x.Id,x.Name,x.Salary}).
Where(x=>x.Salary == "2000");
当我运行上述内容时,我会得到您想要的结果。我跑的时候也得到了相同的结果:
var customers= from c in Customers
where c.Salary == "2000"
select new
{
c.Id,
c.Name,
c.Salary
};