在Code-First迁移脚本中运行SQL查询的替代方法是什么?

发布于 2025-02-03 00:14:03 字数 276 浏览 4 评论 0原文

目标是将数据添加到DB表中。 我可以生成一个空的迁移脚本,然后将其添加到UP()方法中。

  migrationBuilder.Sql($"INSERT INTO [User].[ExtraUser](Id,Name,Description)" +
                    "Values('123','Extra1', 'description')" 

这起作用了,但是在某些情况下,我必须在许多列中添加数据,并且编写插入脚本似乎很不舒服。有更好的选择吗?

Goal is to add data to DB table.
I can generate an empty migrations script and add this in Up() method.

  migrationBuilder.Sql(
quot;INSERT INTO [User].[ExtraUser](Id,Name,Description)" +
                    "Values('123','Extra1', 'description')" 

This works but there are cases where I have to add data in lots of columns and writing insert script seems rather uncomfortable. Is there a better alternative to this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文