C# LInq到SQl问题…请帮助
我有以下数据C# LInq到SQl问题…请帮助,c#,linq-to-sql,C#,Linq To Sql,我有以下数据 ProductId Description cost 12 test 0.0 12 test 8.8 12 test 7.9 27 asdf 9.0 27 asdf 2.0 27 asdf 2.0 我想要下面的结果 12 test 0.0 / test8.8/test 7.9 27 asdf 9.0/as
ProductId Description cost
12 test 0.0
12 test 8.8
12 test 7.9
27 asdf 9.0
27 asdf 2.0
27 asdf 2.0
我想要下面的结果
12 test 0.0 / test8.8/test 7.9
27 asdf 9.0/asdf 2.0/ asdf 2.0
到目前为止我只能想出这个…有人能给我指出正确的方向吗
多谢各位
var n = from c in query
group new {c}
by new
{
c.productid,
c.cost,
c.prodescription
}
into g
select new{
g.Key.productid,
Products=(g.Key.prodescription) + g.Key.cost.ToString()),
};
更好的做法是按照
public override ToString() {
return String.Format("{0}, {1:0.0}", this.Description, this.Cost);
}
并将上面的控制台.WriteLine
替换为
Console.WriteLine(String.Join("/", group.Select(p => p.ToString()).ToArray()));
更好的做法是按照
public override ToString() {
return String.Format("{0}, {1:0.0}", this.Description, this.Cost);
}
并将上面的控制台.WriteLine
替换为
Console.WriteLine(String.Join("/", group.Select(p => p.ToString()).ToArray()));