向匿名 Linq 结果集添加人工行

发布于 2024-08-21 12:26:35 字数 210 浏览 4 评论 0原文

我想知道向匿名 linq 结果集添加人工行的最佳方法是什么。

我有一个 linq 语句,它使用“select new”来形成所需的数据。每条记录都作为具有 ID 和 Name 属性的匿名对象返回。但是,我要求数据的第一行成为 ID = NULL、Name="All" 的对象。

有没有办法将人工结果合并到 Linq 查询中?或者,如何将匿名类型的新实例添加到匿名结果集合中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青朷 2024-08-28 12:26:35

您可以使用Concat方法:

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

You can use the Concat method:

var q = new[]{ new { ID = null, Name = "All" } }.Concat(dbQuery);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文