Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LInq到SQl问题…请帮助_C#_Linq To Sql - Fatal编程技术网

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