2013-04-24 33 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