इकाई फ्रेमवर्क 6 DbContext
में -ContextTypeName
और -MigrationsDirectory
झंडे जोड़कर कई एस के लिए समर्थन जोड़ा गया । मैंने सिर्फ अपने पैकेज मैनेजर कंसोल में कमांड्स को चलाया और नीचे दिए गए आउटपुट को पेस्ट किया ...
यदि DbContext
आपके प्रोजेक्ट में 2 s हैं और आप चलते हैं enable-migrations
, तो आपको एक त्रुटि मिलेगी (जैसा कि आप शायद पहले से जानते हैं):
PM> enable-migrations
More than one context type was found in the assembly 'WebApplication3'.
To enable migrations for 'WebApplication3.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName WebApplication3.Models.ApplicationDbContext.
To enable migrations for 'WebApplication3.Models.AnotherDbContext', use Enable-Migrations -ContextTypeName WebApplication3.Models.AnotherDbContext.
इसलिए आपको enable-migrations
प्रत्येक को DbContext
अलग - अलग चलाना होगा । और आपको Configuration.cs
उत्पन्न होने वाली प्रत्येक फ़ाइल के लिए एक फ़ोल्डर निर्दिष्ट करना होगा ...
PM> Enable-Migrations -ContextTypeName ApplicationDbContext -MigrationsDirectory Migrations\ApplicationDbContext
Checking if the context targets an existing database...
Code First Migrations enabled for project WebApplication3.
PM> Enable-Migrations -ContextTypeName AnotherDbContext -MigrationsDirectory Migrations\AnotherDbContext
Checking if the context targets an existing database...
Code First Migrations enabled for project WebApplication3.
प्रत्येक के लिए माइग्रेशन जोड़ने के लिए DbContext
, आप इसे Configuration
कक्षा के पूरी तरह से योग्य नाम निर्दिष्ट करके ऐसा करते हैं :
PM> Add-Migration -ConfigurationTypeName WebApplication3.Migrations.ApplicationDbContext.Configuration "InitialDatabaseCreation"
Scaffolding migration 'InitialDatabaseCreation'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration InitialDatabaseCreation' again.
PM> Add-Migration -ConfigurationTypeName WebApplication3.Migrations.AnotherDbContext.Configuration "InitialDatabaseCreation"
Scaffolding migration 'InitialDatabaseCreation'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration InitialDatabaseCreation' again.
और आप update-database
उसी तरह से चलते हैं :
PM> Update-Database -ConfigurationTypeName WebApplication3.Migrations.ApplicationDbContext.Configuration
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201402032113124_InitialDatabaseCreation].
Applying explicit migration: 201402032113124_InitialDatabaseCreation.
Running Seed method.
PM> Update-Database -ConfigurationTypeName WebApplication3.Migrations.AnotherDbContext.Configuration
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201402032113383_InitialDatabaseCreation].
Applying explicit migration: 201402032113383_InitialDatabaseCreation.
Running Seed method.
उम्मीद है की यह मदद करेगा।