Home:ALL Converter>Return Multiple Columns in Linq to Sql?

Return Multiple Columns in Linq to Sql?

Ask Time:2009-12-11T08:59:09         Author:chobo2

Json Formatter

How do I return multiple columns with linq to sql in C#?

I tried to end my query with

select new { A.Product, A.Qty };

but this returns some anonymous type and I am not sure what the heck what to do with this, How to return it and how to extract information out of it. I want to put it in some sort of array.

thanks

Author:chobo2,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1885178/return-multiple-columns-in-linq-to-sql
SLaks :

Are you trying to return the data from a method?\n\nIf so, you should just end the query with select A, which will produce the same type that A is.\n\nIf not, you can use the anonymous type the same way you use a regular type.\n\nFor example:\n\nvar results = from ... select new { A.Product, A.Qty };\n\nforeach(var thing in results) {\n Console.WriteLine(\"{0}: {1}\", thing.Product, Thing.Qty);\n}\n\n\nEDIT: To make it into a list, call ToList, like this:\n\nvar resultsList = results.ToList();\n",
2009-12-11T01:03:14
yy