Die EF-Code-Erstbearbeitung (> EF 6.X) funktioniert sehr gut und unterstützt Ihren Anwendungsfall sofort, damit Entwickler Best Practices durch Trennen von DB/EF von Webkontext/-projekten befolgen können . Es geht wirklich darum, die Werkzeuge zu verstehen und die Dinge richtig zu machen. Ich würde Ihnen empfehlen, eine neue Lösung einzurichten, um Code-First-Migrationen zu versuchen. Wenn Sie dies nicht isoliert tun, werfen Sie Ihre Zeit nicht ab, während Sie in Ihrem realen Projekt/Lösung immer wieder testen.
Während Einstellungen Code-erste Migrationen in unserem Projekt wurde mein Team von Microsoft-Mitarbeitern unterstützt. Sie haben es einfach richtig gemacht und wir haben einige Teile in unserer Dokumentation gespeichert.
Während des Surfens im Internet fand ich diese Seiten hilfreich, ich weiß, dass es viel Hilfe bei der Entwicklung und Bereitstellung von EF-Code gibt (besonders bei der Verwendung von Visual Studio im Azure App-Service).
Da Ihre Frage eher schwierig zu beantworten ist, empfehle ich Ihnen, die Best Practices und Dokumentationen für EF 6.X und VS2015 zu befolgen und mit einem besseren Verständnis der Tools, die Sie zur Lösung Ihres Problems benötigen, zu SO zurückzukehren. Dann redigiere entweder deine Frage oder frage einfach eine andere.
Sie einige Vorspeisen geben, auf die Hilfe von migrate.exe anschauen - ein Werkzeug, Code erste Migration von Commandline laufen. Es gibt alles, was Sie wahrscheinlich brauchen.
migrate.exe
Code First Migrations Command Line Utility
Applies any pending migrations to the database.
migrate assembly [configurationType] [contextAssembly] [/targetMigration]
[/startUpDirectory] [/startUpConfigurationFile]
[/startUpDataDirectory] [/connectionStringName]
[/connectionString] [/connectionProviderName] [/force] [/verbose]
[/?]
assembly Specifies the name of the assembly that
contains the migrations configuration type.
[configurationType] Specifies the name of the migrations
configuration type. If omitted, Code First
Migrations will attempt to locate a single
migrations configuration type in the specified
assembly.
[contextAssembly] Specifies the name of the assembly that
contains the DbContext type if different from
the assembly that contains the migrations
configuration type.
[/?] Display this help message.
[/connectionProviderName] Specifies the provider invariant name of the
connection string.
[/connectionString] Specifies the connection string to use. If
omitted, the context's default connection will
be used.
[/connectionStringName] Specifies the name of the connection string to
use from the specified configuration file. If
omitted, the context's default connection will
be used.
[/force] Indicates that automatic migrations which might
incur data loss should be allowed.
[/startUpConfigurationFile] Specifies the Web.config or App.config file of
your application.
[/startUpDataDirectory] Specifies the directory to use when resolving
connection strings containing the
|DataDirectory| substitution string.
[/startUpDirectory] Specifies the working directory of your
application.
[/targetMigration] Specifies the name of a particular migration to
update the database to. If omitted, the current
model will be used.
[/verbose] Indicates that the executing SQL and additional
diagnostic information should be output to the console window
Nach welchen Konfigurationsparameter Sie Sie die Migration Werkzeuge passieren entweder eine explizite, eine Konfigurationsdatei auf Basis laufen oder eine Konvention basierte Migration. Achten Sie auf, was zu migrieren druckt als Ausgabe von Origin
1. Explizite Parameter
migrate.exe "Fireframework.Web.dll" "Fireframework.Web.Migrations.Configuration" /connectionString="Data Source=tcp:fireframeworkdbs.database.windows.net,1433;Initial Catalog=fireframeworkdbdev;User [email protected];Password="secret" /connectionProviderName="System.Data.SqlClient" /verbose
2016-04-25T08:06:09.9183260Z VERBOSE: Target database is: 'fireframeworkdbdev' (DataSource: tcp:fireframeworkdbs.database.windows.net,1433, Provider: System.Data.SqlClient, **Origin: Explicit**).
2016-04-25T08:06:13.5640428Z No pending explicit migrations.
2.Durch die Konfiguration
migrate.exe "Fireframework.Web.dll" "Fireframework.Web.Migrations.Configuration" /startUpConfigurationFile="web.config" /verbose
VERBOSE: Target database is: 'fireframework' (DataSource: (LocalDb)\MSSQLLocalDB, Provider: System.Data.SqlClient, **Origin: Configuration**).
Applying explicit migrations: [201603161334138_InitialCreate, 201604081002396_Add_Simulation_CreatedDateTime_Property, 201604201138442_Add_Simulation_AbortRequestPending_Property, 201604211315107_Rename_Simulation_Properties].
Applying explicit migration: 201603161334138_InitialCreate.
3. Mit dem Übereinkommen
migrate.exe "Fireframework.Web.dll" "Fireframework.Web.Migrations.Configuration"
VERBOSE: Target database is: 'Fireframework.Model.DatabaseContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, **Origin: Convention**).
Vielen Dank für Sie exaaustive exaustive Antwort, aber ich habe bereits alles getan, was Sie mir raten, zu tun. Das Problem ist, dass die erste Migrationsoption von Code fehlt, da Visual Studio meinen Kontext nicht als CodeFirst-Typ erkennt und für den Moment keine Lösung gefunden hat. – Androidian
Bitte fügen Sie relevante Teile wie und Ihrer web.config zu Ihrer Frage hinzu, damit die Leute Ihr spezifisches Problem debuggen können. Diese Teile werden am Ende des ContosoUniversity EF Code-First-Tutorials angezeigt. –
Die Struktur ist ein wenig artikuliert und das Problem kann alles sein (denke ich), also teile ich Ihnen lieber den Link zu meinem gdrive freigegebenen Ordner, der das Projekt enthält: https://drive.google.com/open?id=0B -vx6bPPHKprVHdaVURPbkdUZXM. Es scheint, dass einige Abhängigkeiten das Problem verursachen, aber ich habe nicht herausgefunden, welche. Bitte, wenn Sie einen Blick auf mein Projekt werfen können. – Androidian