Click here to Skip to main content
15,888,527 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionBinding selected value of Dropdownlist to Grid Pin
indian1433-Jul-18 12:58
indian1433-Jul-18 12:58 
AnswerRe: Binding selected value of Dropdownlist to Grid Pin
Vincent Maverick Durano3-Jul-18 16:20
professionalVincent Maverick Durano3-Jul-18 16:20 
Question.Net Core 2.1 IHostingEnvironment, how to access it Pin
jkirkerx28-Jun-18 20:14
professionaljkirkerx28-Jun-18 20:14 
AnswerRe: .Net Core 2.1 IHostingEnvironment, how to access it Pin
Richard Deeming29-Jun-18 0:00
mveRichard Deeming29-Jun-18 0:00 
GeneralRe: .Net Core 2.1 IHostingEnvironment, how to access it Pin
jkirkerx29-Jun-18 6:18
professionaljkirkerx29-Jun-18 6:18 
Question.Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
jkirkerx28-Jun-18 9:02
professionaljkirkerx28-Jun-18 9:02 
AnswerDirectory.GetCurrentDirectory Pin
jkirkerx28-Jun-18 9:11
professionaljkirkerx28-Jun-18 9:11 
AnswerRe: .Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
Richard Deeming28-Jun-18 10:26
mveRichard Deeming28-Jun-18 10:26 
The code in Startup runs as part of the BuildWebHost method in the Program class. That gets invoked both by the application, and by the design-time EF commands (add-migration, update-database, etc.), so you can't seed the data in the Startup class.
In 2.0 projects using EF Core 2.0, Program.BuildWebHost is invoked to obtain the application services. Unlike 1.x, this has the additional side effect of invoking Startup.Configure. If your 1.x app invoked database initialization code in its Configure method, unexpected problems can occur.

So the seeding code needs to be in Main, on in the context's OnModelCreating method[^].

In theory, you should be able to inject any registered service into your DbContext constructor, which would let you access your ServerPath service from the OnModelCreating method.

Alternatively, you can retrieve the services from the Main method using services.GetRequiredService<ServerPath>(); within the try block.

(Personally, I tend to keep the migrations and seed data in a separate console app, because I don't want the website connecting to SQL using an account that has permissions to create and modify databases.)



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: .Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
jkirkerx28-Jun-18 11:56
professionaljkirkerx28-Jun-18 11:56 
QuestionSenior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx27-Jun-18 8:42
professionaljkirkerx27-Jun-18 8:42 
AnswerRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
F-ES Sitecore27-Jun-18 23:44
professionalF-ES Sitecore27-Jun-18 23:44 
GeneralRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx28-Jun-18 6:50
professionaljkirkerx28-Jun-18 6:50 
AnswerRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
Richard Deeming28-Jun-18 1:03
mveRichard Deeming28-Jun-18 1:03 
GeneralRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx28-Jun-18 6:55
professionaljkirkerx28-Jun-18 6:55 
Question.net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment Pin
jkirkerx27-Jun-18 7:14
professionaljkirkerx27-Jun-18 7:14 
AnswerRe: .net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment Pin
Richard Deeming27-Jun-18 7:45
mveRichard Deeming27-Jun-18 7:45 
GeneralRe: .net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment [solved] Pin
jkirkerx27-Jun-18 8:08
professionaljkirkerx27-Jun-18 8:08 
QuestionBody Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
jkirkerx27-Jun-18 6:26
professionaljkirkerx27-Jun-18 6:26 
AnswerRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
Richard Deeming27-Jun-18 7:13
mveRichard Deeming27-Jun-18 7:13 
GeneralRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
jkirkerx27-Jun-18 8:13
professionaljkirkerx27-Jun-18 8:13 
GeneralRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
Richard Deeming27-Jun-18 8:18
mveRichard Deeming27-Jun-18 8:18 
Question.Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
jkirkerx25-Jun-18 12:14
professionaljkirkerx25-Jun-18 12:14 
AnswerRe: .Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
F-ES Sitecore26-Jun-18 0:03
professionalF-ES Sitecore26-Jun-18 0:03 
GeneralRe: .Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
jkirkerx26-Jun-18 6:33
professionaljkirkerx26-Jun-18 6:33 
AnswerRe: .Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
Richard Deeming26-Jun-18 1:37
mveRichard Deeming26-Jun-18 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.