开发者

Adding an artificial row to an anonymous Linq resultset

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜