2
Answers

how to change model without losing data in entity framework

please tell me  how to change model in entity framework  without losing data in existing database . when we change model first database deleted and then create new database and i lost existing data.
 
Answers (2)
2
Ravi Patel

Ravi Patel

NA 7.8k 532.4k 8y
Hi,
I hope you are talking about code first approach
once you create database using code first approach then after that if you want to change the model class . that reflect your database
if you do not want loose any column value then use migration
here is step
open your package manager console type the following comand
1. enable-migrations
2. add-migration
3. update-database
when ever you change the model class repeat the second and third step
 
for more details  check this
 
http://www.c-sharpcorner.com/UploadFile/4b0136/perform-code-first-migration-in-Asp-Net-mvc-5/ 
0
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
I think you are saying about Migration.
Visit here:-
http://www.dotnet-tricks.com/Tutorial/entityframework/R54K181213-Understanding-Entity-Framework-Code-First-Migrations.html