I currently have an ASP.NET MVC 3 project, plus a class library project, that I am planning on open-sourcing. Before I do that though I want to clean up the project a little bit. One modification I want to make is with the database. Currently the site is published to a shared hosting server and I setup the SQL database on that server. However, since people will be forking the project and running it locally I'd like to just attach a SQL server express database or something that is part of the project. I want people to clone the repository, open the project, press F5 and have it run. Currently they'd have to setup a SQL database and create all the tables and stuff.
The solution consists of two projects: MvcUI and Domain. Domain is where all the application logic occurs. In fact, the domain is UI agnostic which means that it could be consumed by a desktop application just as easily as it could be by a web application.
I would like the database to be part of the Domain (class library) project. I have never done this before. If anyone could provide a simple explanation for how I would need to go about setting this up I would be thrilled. It would be very nice to have the database just be a in the solution because I could pre-populate it with some basic data. What do I need to do to get this database in my project as a database file or what not?
From the Add New Item window, select ADO.NET Entity Data Model and set its Name as NorthwindModel and then click Add. Then the Entity Data Model Wizard will open up where you need to select EF Designer database option. Now the wizard will ask you to connect and configure the Connection String to the database.
Add a data sourceIn the Data Sources window, select Add New Data Source. The Data Source Configuration Wizard opens. On the Choose a Data Source Type page, choose Database and then choose Next.
Visual Web Developer automatically creates the database in the App_Data folder.
SQL Server Compact Edition is a portable SQL database that should do exactly what you are asking.
Microsoft SQL Server Compact 4.0 is a free, embedded database that software developers can use for building ASP.NET websites and Windows desktop applications. SQL Server Compact 4.0 has a small footprint and supports private deployment of its binaries within the application folder, easy application development in Visual Studio and WebMatrix, and seamless migration of schema and data to SQL Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With