Back-End Development

Adding a Database Project to a .NET MVC Framework Web Application

Man Working At His Computer

For an updated tutorial with GIFs, click here.

We are going to be continuing from where we left off in the last post. If you are trying to follow along and want to take a look at how I set up the folder structure, click here.


  1. Create a SQL server database project and configure the path to the ’04 – Database’ folder (or whichever folder you want to place it in).
  2. Add an existing project in the Visual Studio.
  3. Add scripts and table files.


  1. Create a new SQL Server Database Project. This is the database where the schema and the scripts will go.

B2 P8

  1. Name your project and configure the path to the ’04 – Database’ folder we created earlier. I will name it ‘Demo_01.Database’ in this example.

B2 P9

Demo_01.Database project will open up but simply close it and go back to the original Demo_01.sln file. However, you will notice that the .Database project you just created is not visible in the solution.

B2 P10

  1. Right click the solution and Add an Existing Project. Locate the SQL server database project you created in Step 1 and click ‘Open’.

B2 P11

B2 P12

  1. Drag the .sqlproj file you just opened into the “04 – Database” folder and right click that .sqlproj file to create sub-folders called “Tables” and “Scripts”.
Covid 19
COVID-19: Digital Insights For Enterprise Action

Access Perficient’s latest insights into how you can leverage digital technologies to not only respond to the pandemic, but drive your operations forward and deliver experiences your customers need.

Get Informed

B1 4 Tablescript

  1. Right click the Tables folder to add a Table and the Scripts folder to add a Script (Not in build) & Post Deployment Script.
  • Table is where the columns will be defined.
  • Scripts are where the data will be seeded (empty when you first publish the tables).
  • Post deployment script will run once the tables are deployed. This script includes simple commands to allow each of the seed scripts to run and you NEED this.

B2 P13

B2 P14

B2 P15

B2 P16


Below are examples of how each of the three files would look like.

B2 P17

Again, the script file is empty the first time you publish it. This is how the script would appear when you need to seed the data afterwards.

B2 P18

Simply add ‘:r .{script name}.sql. You can ignore the red lines with the Post Deployment script file if they appear.

B2 P19

That is all you have to do to add the database project to your .NET MVC Web Application!

About the Author

David Hwang is an Associate Technical Consultant in the Sitecore/Microsoft Business Unit. He will be blogging about various concepts in technologies for beginners.

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up