当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Grouping using LINQ - returning zero records

问题描述:

I'm currently learning about LINQ amongst other things, but am having trouble grouping. I simply want to display unique values within the combobox for TxtProductFamily. I am getting zero entries in the dropdown:

var sel = (from o in db.r2_machine group o by o.product_family).ToList();

TxtProductFamily.ItemsSource = sel;

网友答案:

you have to do like this:

var sel = (from o in db.r2_machine 
           group o by o.product_family into g
           select g.Key).ToList();
TxtProductFamily.ItemsSource = sel;
网友答案:

You are not selecting any data after grouping. Use Select method.

  var sel = (from o in db.r2_machine 
             group o by o.product_family into g 
             select g.Key).ToList();

  TxtProductFamily.ItemsSource = sel;
网友答案:

You must select something to get output

var outPut= (from o in db.r2_machine 
           group o by o.product_family into g
           select g).ToList();
TxtProductFamily.ItemsSource = outPut;
分享给朋友:
您可能感兴趣的文章:
随机阅读: