开发者

Adding an artificial row to an anonymous Linq resultset

开发者 https://www.devze.com 2022-12-19 17:29 出处:网络
I\'m wondering what the best approach to adding an artificial row to an anonymous linq result set would be.

I'm wondering what the best approach to adding an artificial row to an anonymous linq result set would be.

I have a linq statement which uses "select new" to form the data required. Each record comes back as an anonymous object with ID and开发者_如何学运维 Name properties. However, I require that the first row of the data becomes an object with ID = NULL, Name="All".

Is there a way to union in an artificial result into the Linq query? Or else, how do I add a new instance of the anonymous type into the anonymous result collection?


You can use the Concat method:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号