Convert IQueryable<> type object to List type?

前端 未结 5 1763
广开言路
广开言路 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:48

    The List class's constructor can convert an IQueryable for you:

    public static List ToList(this IQueryable source)
    {
        return new List(source);
    }
    

    or you can just convert it without the extension method, of course:

    var list = new List(queryable);
    

提交回复
热议问题