я изменяю ConnectionStrings с AttachDBFileName:
"ConnectionStrings": {
"MvcMusicStoreContext":
//"Server=(localdb)\\mssqllocaldb;Database=MvcMusicStoreContext;Trusted_Connection=True;MultipleActiveResultSets=true"
"Server=(localdb)\\MSSQLLocalDB;AttachDBFilename=[DataDirectory]\\App_Data\\MvcMusicStoreContext.mdf;Trusted_Connection=True;MultipleActiveResultSets=true"
}
и в ConfigureServices при запуске:
string path = Directory.GetCurrentDirectory();
services.AddDbContext<MvcMusicStoreContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MvcMusicStoreContext")
.Replace("[DataDirectory]",path)));