forked from fluentmigrator/fluentmigrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Raw Sql Helper for inserting data
daniellee edited this page Jan 30, 2013
·
1 revision
When using the Insert.IntoTable expression, all row data that is a string is quoted and saved in the database. If you want to use an sql expression instead then the RawSql helper class is what you need.
For example, if I want to use an SqlServer 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 Postgres).
- Getting FluentMigrator
- How to create a Migration
- Fluent Interface
- Migration Runners
- Use inbuilt database functions when setting the default value
- Sql Server Specific Extensions
- Raw Sql Helper for inserting data
- Auto Reversing Migrations
- Resharper File Template
- Transaction Modes for the Migration Runner
- ApplicationContext: Passing parameters to Migrations
- Dealing with Multiple Database Types
- Filter migrations run based on Tags
- Enforce migration version numbering rules
- Create custom metadata for the VersionInfo table