c# - How can I extract a list of Tuple from a specific table with Entity Framework / LINQ? -
i need extract list of couple 'id'/'name' large table in c# .net entity framework.
i try request :
list<tuple<int, string>> list = (from res in db.resource select new tuple<int, string>(res.resource_id, res.name)).tolist();
but unfortunately i've got error :
only parameterless constructors , initializers supported in linq entities.
i don't undestand how can extract list of tuple framework , feel bit lost error. can me understand , resolve problem ?
best regards,
alex
you can middle-step selecting anonymous type:
db.resource.select(x => new { x.resource_id, x.name }).asenumerable().select(x => tuple.create(x.resource_id, x.name)).tolist();
creating tuple not supported operation in linq entities, have select anonymous type, equivalent to:
select [resource].[resource_id], [resource].[name]
then move linq objects asenumerable
, tuple.
Comments
Post a Comment