Specify the location of SQL Server files when using Entity Framework Database.Create ()

I have several Entity Framework Code First DbContext objects that use a custom initializer.

In the initializer call

context.Database.Create(); 

creates a database in SQL Server.

Data and log files are created in directories based on database parameters in SQL Server.

I would like different subclasses of DbContext to have different paths to the data and log files. Can I specify the paths somehow when creating the database, or should I detach / move / attach in a separate step after creating the database?

+6
source share
1 answer

You can always use the AttachDBFilename keyword in the connection string. See the SqlConnection.ConectionString documentation for more information.

+3
source

Source: https://habr.com/ru/post/919208/


All Articles