Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Migration API

Hi i have made a data sync project on top of entity framework. the framework is schema independent to some extent. i want to make it more tolerant to changes in schema even the currently considered breaking changes.

to achieve this i will have to get inside the ef migration engine and will have to generate a command like

add-transformation 


which will be detecting the changes and creating a transformation.

I have looked into the source code of ef 6 but couldnt find an appropriate place to start. any help would be appreciated.

Edit 1 :- answer to questions received in the comments

  1. Code First Approach
  2. Extent:
    Changes in data will be handled by the migration so no need to incorporate the changes. What I need to is a way to execute a command like add-transformation which would create a new transformation like a new migration. So typically lets say i have a database model (domain model) like

    class A { public int a {get; set;} public int b {get; set;} }

then i change the class to the structure

class A 
{
 public int a {get; set;}
 public int b {get; set;}
 public int c {get; set;}
}

and then i run add-tranformation ClassChangesA
the code i require should

1. Detect changes
2. Generate a class like the migration class. Ex.

class Transformation_112334_ClassChangesA
{
 public A Up(OldA model){
   //Property C added
 }
 public OldA Down(A model){
   //Property C removed
 }
}
like image 348
Parv Sharma Avatar asked Mar 18 '17 05:03

Parv Sharma


People also ask

How do I enable migration in Entity Framework?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).


1 Answers

I believe that the command you are looking for is add-migration migration_name then you can update your database using the command update-database, this is how to work with code first migrations in entity framework.

like image 68
SEDaradji Avatar answered Nov 15 '22 10:11

SEDaradji