Search⌘ K
AI Features

Embedding SQL Scripts in Our Project

Explore embedding SQL scripts as project resources to enable automated database migrations using DbUp and Dapper. Understand how to organize scripts, execute migrations, and maintain schema versioning to keep your database synchronized with your application.

In the previous subsection, we told DbUp to look for SQL Scripts that have been embedded in our project. Now, we are going to embed SQL Scripts for the tables and stored procedures in our project so that DbUp will execute them if they haven’t already been executed when our app loads:

  1. In “Solution Explorer”, right-click the project and choose “Add | New Folder”. Enter “SQLScripts” as the folder name.

  2. Right-click the “SQLScripts” folder and choose “Add | New Item…”

  3. In the dialog box that appears, select the “General” tab and then “Text Fileand enter 01-Tables.sql as the filename:

Adding a SQL file to a Visual Studio project
Adding a SQL file to a Visual Studio project
  1. Copy the contents of the script from ...