Returning multiple columns in Linq to Sql?

How to return multiple columns from linq to sql in c #?

I tried to complete my request with

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

but this returns some kind of anonymous type, and I'm not sure what to do with it, how to return it and how to extract information from it. I want to put it in some kind of array.

thank

+3
source share
2 answers

Are you trying to return data from a method?

If so, you should just end the request with the help select A, which will create the same type as A.

If not, you can use an anonymous type just like you use a regular type.

For instance:

var results = from ... select new { A.Product, A.Qty };

foreach(var thing in results) {
    Console.WriteLine("{0}: {1}", thing.Product, Thing.Qty);
}

EDIT . To do this in a list, call ToList, for example:

var resultsList = results.ToList();
+6
source

Call list () on request

0
source

Source: https://habr.com/ru/post/1725357/


All Articles