Adding an artificial string to an anonymous Linq result set

I am wondering what the best approach to adding an artificial string to an anonymous linq result set would be.

I have a linq statement that uses "select new" to generate the required data. Each record is returned as an anonymous object with identifiers and names. However, I require the first row of data to become an object with ID = NULL, Name = "All."

Is there a way to combine into an artificial result in a Linq query? Or, how to add a new instance of an anonymous type to an anonymous collection of results?

+4
source share
1 answer

You can use the Concat method:

var q = new[]{ new { ID = null, Name = "All" } }.Concat(dbQuery); 
+3
source

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


All Articles