2013-04-24 50 views
0

所以,球员......我有这样的疑问:Linq to SQL - 输出类型? (不显示信息只显示型)

Allow the user view the top five selling products in descending order grouped by country.

这里是我的代码有:

var q6 = (from t in northwind.Products 
      join o in northwind.Suppliers on t.SupplierID equals o.SupplierID 
      group t.UnitPrice by new {o.Country, t.UnitPrice} into grouped 
      let county = grouped.Key.Country 
      let price = grouped.Key.UnitPrice 
      group new 
      { 
       Country = county, 
       Product = price 
      } 
      by county 
      into countryGrouped 
      select new 
      { 
       Output = countryGrouped.Key, 
       Price = countryGrouped.OrderBy(c => c.Product) 
      });     

     lbxTop5.ItemsSource = q6; 

它的工作原理就像输出价格一样。

价格出来是这样的:

Image of output type

谁能告诉我如何输出价格以适当的格式,而不是数据类型?

谢谢!

+0

这可能与你指定的控制 – codingbiz 2013-04-24 16:52:58

回答

0

什么是 “propper格式”?

你可以做这样的事情:

... 
select new 
{ 
    Output = countryGrouped.Key, 
    Price = string.Join(",", countryGrouped.OrderBy(c => c.Product)) 
}); 

这将使输出一个逗号分隔的字符串

+0

的DISPALY字段和值字段做小数点会很好,但只要它显示出来就没有什么区别! 此代码可以帮助!非常感谢你。唯一的是它重复了一些数据,但我会解决这个问题!谢谢! – 2013-04-24 17:06:22