使用序列在 Fluent Migrator 中插入值
Insert values in Fluent Migrator with sequence
有什么方法可以使用 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" });
我该怎么做才能获得下一个验证序列?
任何帮助将不胜感激
谢谢!
Insert.IntoTable("TEST_TABLE ").Row(new { SEQ_NO = RawSql.Insert(0), DUMMY = "TEST"});
插入 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' });
这将导致用户名列被设置为当前用户名。请注意,通过使用 sql 服务器特定函数,如 CURRENT_USER,此表达式不再可移植,并且不会对另一个数据库(如 PostgreSQL)起作用。
原始 SQL 助手
使用 Insert.IntoTable 表达式时,或设置默认列值时,所有为字符串的行数据都被引用并保存在数据库中。如果您想使用 sql 表达式,那么您需要 RawSql 帮助程序 class。
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).
有什么方法可以使用 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" });
我该怎么做才能获得下一个验证序列?
任何帮助将不胜感激
谢谢!
Insert.IntoTable("TEST_TABLE ").Row(new { SEQ_NO = RawSql.Insert(0), DUMMY = "TEST"});
插入 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' });
这将导致用户名列被设置为当前用户名。请注意,通过使用 sql 服务器特定函数,如 CURRENT_USER,此表达式不再可移植,并且不会对另一个数据库(如 PostgreSQL)起作用。
原始 SQL 助手 使用 Insert.IntoTable 表达式时,或设置默认列值时,所有为字符串的行数据都被引用并保存在数据库中。如果您想使用 sql 表达式,那么您需要 RawSql 帮助程序 class。
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).