Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:50:18+00:00 2026-05-31T10:50:18+00:00

i have added the following initializer for my asp.net web application :- namespace Learning.DAL

  • 0

i have added the following initializer for my asp.net web application :-

namespace Learning.DAL
{
public class SchoolInitializer : DropCreateDatabaseIfModelChanges<LearningContext>
{
protected override void Seed(LearningContext context)
{
var students = new List<Student>
{
new Student { FirstMidName = "test", LastName = "test2",
EnrollmentDate = DateTime.Parse("2012-01-01") },
//code does here

but i have the following questions that i need some help:-

  1. If the application is on production when will the application checks if IfModelChanges and re-create the Db accordingly? only when i stop and re-run the server, or when a specific page is visited by the first user?

  2. will dropping and re-creating the database causes the data that are already there to be deleted?

  3. if i remove a property from an entity set in my new changes what will happen to its data?

  4. if i add a non-nullable property to an exsiting entity set, what will happen when the database is dropped and re-created ?
    BR

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:50:19+00:00Added an answer on May 31, 2026 at 10:50 am

    If the application is on production when will the application checks
    if IfModelChanges and re-create the Db accordingly? only when i stop
    and re-run the server, or when a specific page is visited by the first
    user?

    IIS recycles AppDomains periodically. EF caches its model once per app domain. Hence when your application is recycled and your application uses the context for the first time EF will run your initializer. So at that point if the model is different from the database your SchoolInitializer will be executed.

    will dropping and re-creating the database causes the data that are
    already there to be deleted?

    Yes. Only the data inserted in your Seed method will be there after the recreation of database.

    if i remove a property from an entity set in my new changes what will
    happen to its data?

    if i add a non-nullable property to an exsiting entity set, what will
    happen when the database is dropped and re-created ?

    EF detects that the model has been changed and database will be dropped and re-created.

    My advice is, database initializers are preferred in development environment. For production it will be better to create the database using a script. This will be useful in change management. You can also look at database migrations feature in EF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simplified ViewModel public class UserViewModel : IUserViewModel { public DelegateCommand<object>
I have a internal website hosted on IIS. I added the following meta code
Okay, so i have the following html added to a site using javascript/greasemonkey. (just
I have a data file that looks like the following example. I've added '%'
I have following code in my deploy.rb namespace :app do desc copies the configuration
I'v got the following code : public class MyModule: IModule { private IRegionManager mRegionManager
I have done the following steps: Added to gemfile: gem recaptcha Added to config/initializers/recaptcha.rb
I have added CRM 2011 (on-premises) Deployment and Discovery Services as web Reference (instead
In C++, I want to have a class whose constructors are the following: class
I have a Windows Forms application built using the .NET 3.5 Framework which self

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.