c# - 使用序列在 Fluent Migrator 中插入值
问题描述
有没有办法Fluent Migrator
在数据库中使用我的序列插入一行?
前任。我想执行这个命令:
insert into TEST_TABLE (ID, DUMMY) values (seq_test.nextval, 'TEST')
我的顺序:
seq_test
我试过的:
Insert.IntoTable("TEST_TABLE").Row(new { /*Sequence Here*/, DUMMY = "Test" });
我该怎么做才能让我的序列下一个 val?
任何帮助,将不胜感激
谢谢!
解决方案
插入 TEST_TABLE (ID, DUMMY) 值 (seq_test.nextval, 'TEST')
如果这是 oracle 序列
RawSql.Insert("seq_test.nextval from dual"), should do mix.
Insert.IntoTable("User").Row(new { ID = RawSql.Insert("seq_test.nextval from dual"),DUMMY ='test' });
或者
Insert.IntoTable("User").Row(new { ID = RawSql.Insert("select seq_test.nextval"),DUMMY ='test' });
这将导致将用户名列设置为当前用户名。请注意,通过使用诸如 CURRENT_USER 之类的 sql server 特定函数,此表达式不再可移植,并且无法针对另一个数据库(如 PostgreSQL)工作。
原始 SQL 帮助程序 使用 Insert.IntoTable 表达式或设置默认列值时,所有作为字符串的行数据都会被引用并保存在数据库中。如果您想改用 sql 表达式,那么 RawSql 助手类就是您所需要的。
For example, if I want to use a Microsoft SQL Server function like CURRENT_USER and try to insert like this:
Insert.IntoTable("Users").Row(new { Username = "CURRENT_USER" });
The result will be that the Username column will get the value CURRENT_USER as a string. To execute the function you can use the RawSql.Insert method like this:
Insert.IntoTable("User").Row(new { Username = RawSql.Insert("CURRENT_USER") });
This will result in the Username column being set to the current username. Be aware that by using an sql server specific function like CURRENT_USER that this expression is not portable anymore and will not work against another database (like PostgreSQL).
推荐阅读
- checkbox - xamarin 表单 xlabs 复选框
- java - 如何将csv数据集的多列存储在java中的单个变量中,以便该变量可以用作ml模型的输入特征
- objective-c - 在 UINavigation 项目标题视图中添加带有 UILabel 和 UIImageView 的 UICollectionView
- nodatime - 如何在 ASP.NET Core 2.1 中全局格式化 NodaTime 日期字符串?
- javascript - 如何设置更大的负值以在莫里斯条形图中显示更短的条形?
- android - Gmail 应用,例如带有 NavigationDrawer 的片段导航
- javascript - 为什么我的变量显示为空?
- javascript - 如何在大型商业产品库中添加鼠标图像滚动器?
- django - 您可以为 DetailsView 使用禁用的表单吗?
- php - 使用 SMTP 在 PHP 中发送电子邮件得到空白页面