I have several Entity Framework Code First DbContext objects that use a custom Initializer.
In the initializer, the call to
context.Database.Create();
creates the database in SQL Server.
The Data and Log files are created in directories per the Database Settings in SQL Server.
I would like different DbContext subclasses to have different Data and Log file paths. Can I specify the paths somehow when creating the database, or must I detach/move/attach in a separate step after the database has been created?
If you want to change the connection string go to the app. config and remove all the connection strings. Now go to the edmx, right click on the designer surface, select Update model from database, choose the connection string from the dropdown, Click next, Add or Refresh (select what you want) and finish.
However, with ASP.NET you can use Entity Framework to generate a database based on an object model. Generally you would create an ER diagram and manually create all the tables one by one. With Entity Framework, you can create your entities in Visual Studio and all your tables will be created for you.
You can always use the AttachDBFilename
keyword in the connection string. See the documentation of SqlConnection.ConectionString
for more information.
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