asp.net - Entity Framework migrations and refactor model into separate project -


i started out asp.net mvc project entity framework code first , migrations enabled. using standard template got model in same project rest of web site. want re-use model in project, cannot find step-by-step recipe how move model , migrations history, separate project. biggest concerns database comes out of sync model, or data in database lost. maybe it's nothing afraid of, i'll happy if can share experience!

ok when have migrations turned on can move context, associated entities , migration configurations new project no problem. if leave of namespaces should not need change anything. because key migration history in database based on namespace + class of migration configuration file. example in web application have migrations @

codemigrations.migrations  

so contextkey in __migrationhistory table ends being

codemigrations.migrations.configuration 

if move code new project , leave namespaces nothing need changed, if want namespaces updated reflect new base namespace of new project need update rows in __migrationhistory table, changing contextkey new name.

for example if moved mine web project named codemigrations project called codemigrations.model need update __migrationhistory table follows:

update [dbo].[__migrationhistory]     set      [contextkey] = 'codemigrations.model.migrations.configuration'       [contextkey] = 'codemigrations.migrations.configuration' 

after doing migration history should associated new project now


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -