Last active
November 10, 2019 11:42
-
-
Save tonysneed/e437e698164cd9e41176 to your computer and use it in GitHub Desktop.
ASPNetCore: App_Data with LocalDb File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Data": { | |
"SampleDb": { | |
"ConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\SampleDb.mdf;Integrated Security=True; MultipleActiveResultSets=True" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) | |
{ | |
// Set up configuration sources ... | |
// Set up data directory | |
string appRoot = appEnv.ApplicationBasePath; | |
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(appRoot, "App_Data")); | |
} |
Blog post on EF6 with AspNetCore: http://blog.tonysneed.com/2016/01/22/ef6-asp-net-core-mvc6
Updated Startup to use IApplicationEnvironment
ctor parameter instead of static methods.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full solution is here: https://github.com/tonysneed/Demo.AspNetCore.EF6.