如何加入Linq dan显示如gridview中的树

时间:2017-03-03 13:43:30

标签: c# linq gridview

public class category {
    int Id { get; set; }
    string c_name { get; set; }
}
public class item {
    int id { get; set; }
    string item_name { get; set; }
    int category_id { get; set; }
}

记录

 // |  id   |   c_name    |        |  id  | item_name  | category_id |
 // |   1   |   fruit     |        |   1  | apple      |      1      |
 // |   2   |   electronic|        |   2  | banana     |      1      |
 //                                |   3  | rice cooker|      2      |

如何在列表中加入Linq并在树状结构中显示?

var c = new List<category>();
var i = new List<item>();

1 个答案:

答案 0 :(得分:0)

您可以加入以下表格:

var q = from ci in c
    join ii in i on ci.id equals ii.id
    select new { category = ci, item = ii};