Convert IQueryable<> type object to List type?

前端 未结 5 1761
广开言路
广开言路 2020-12-02 22:02

I have IQueryable<> object.

I want to Convert it into List<> with selected columns like new { ID = s.ID, Name = s.Name }<

5条回答
  •  天命终不由人
    2020-12-02 22:30

    Then just Select:

    var list = source.Select(s=>new { ID = s.ID, Name = s.Name }).ToList();
    

    (edit) Actually - the names could be inferred in this case, so you could use:

    var list = source.Select(s=>new { s.ID, s.Name }).ToList();
    

    which saves a few electrons...

提交回复
热议问题