Projecting into KeyValuePair via EF / Linq

后端 未结 3 1169
长发绾君心
长发绾君心 2021-01-03 18:21

I\'m trying to load a list of KeyValuePairs from an EF / Linq query like this:

return (from o in context.myTable 
select new KeyValuePair

        
3条回答
  •  梦毁少年i
    2021-01-03 18:31

    Since LINQ to Entities does not support KeyValuePair, you should turns to LINQ to Object by using AsEnumerable first:

    return context.myTable
                  .AsEnumerable()
                  .Select(new KeyValuePair(o.columnA, o.columnB))
                  .ToList();
    

提交回复
热议问题