به 4 روش متفاوت می توانیم دیتابیس را تنظیم اولبه و داده دهی نماییم.

There are four different database initialization strategies:

  1. CreateDatabaseIfNotExists: This is default initializer. As the name suggests, it will create the database if none exists as per the configuration. However, if you change the model class and then run the application with this initializer, then it will throw an exception.
  2. DropCreateDatabaseIfModelChanges: This initializer drops an existing database and creates a new database, if your model classes (entity classes) have been changed. So you don't have to worry about maintaining your database schema, when your model classes change.
  3. DropCreateDatabaseAlways: As the name suggests, this initializer drops an existing database every time you run the application, irrespective of whether your model classes have changed or not. This will be useful, when you want fresh database, every time you run the application, like while you are developing the application.
  4. Custom DB Initializer: You can also create your own custom initializer, if any of the above doesn't satisfy your requirements or you want to do some other process that initializes the database using the above initializer.

روش اول که بصورت پیش فرض بر روی خود Asp.Net MVC تنظیم است ولی باز می توانیم ان را دوباره نویسی کنیم که هیچ تفاوتی نمی کند و تنها در زمان داده دهی اولیه بهتر است استفاده گردد که این روش تنها یک بار انجام می گردد و دیگر اتفاق نمی افتد.

 

روش دوم در زمان هایی مورد استفاده قرار می گیرد که اگر دیتابیس اطلاعاتش تغییر یابد دوباره آن را از بین ببرد و مجددا با اطلاعات جدید ایجاد می کند.

 

و در روش سوم هم اصلن به ایجاد شدن تغییر در دیتابیس اهمیتی نمیدهد و به صورت همیشگی اطلاعات را دوباره نویسی میکند و اطلاعات حذف شده و یا اضافه و ویرایش شده را پاک میکند و اطلاعات اولیه جایگزین می گردد.

 

در روش اخر با توجه به نیاز های کاربر قابلیت تنظیم کردن به صورت شخصی بر روی دیتابیس مهیا شده است که البته روش های پیچیده تری نسبت به بقیه موارد را دارا می باشد.