How can I extract a list of Tuple from a specific table with Entity Framework / LINQ?

前端 未结 2 1900
闹比i
闹比i 2020-12-19 01:47

I need to extract a list of couple \'ID\'/\'Name\' from a large table in C# .NET with Entity Framework.

I try this request :

List

        
2条回答
  •  情话喂你
    2020-12-19 02:28

    You can create a list from db.Resource and use LINQ to Collections to erase this limitation:

    var list = db.Resource.ToList().Select(res => Tuple.Create(res.Resource_ID, res.Name));
    

    The Tuple class does have some constructors (up to 8 items), but the Create() helper method makes the creation more straightforward.

提交回复
热议问题