Ich benutze Code-First, erstelle eine Website mit der Standardvorlage und füge dann dem applicationDBContext
Tabellen hinzu. Wenn ich jetzt Enable-Migrations in Package Manager Console I gehe erhalten
In der Assembly 'DOC' wurde kein Kontexttyp gefunden.
und wenn ich den vollständigen Pfad mit:
ContextTypeName Option enable-migrations -ContextTypeName DOC.Migrations.Configuration
...Ich bekomme:
Migrationen wurden bereits in Projekt 'DOC' aktiviert. Verwenden Sie den Parameter -Force, um die vorhandene Migrationskonfiguration zu überschreiben.
Und wenn ich -Force gehe, heißt es
Code First Migrations für Projekt DOC aktiviert.
aber wenn ich versuche, add-migration zu bekommen, bekomme ich
Fehler CS0311 Der Typ 'DOC.Migrations.Configuration' kann nicht als Typparameter 'TContext' in der generischen Art oder Methode 'DbMigrationsConfiguration' verwendet werden. Es findet keine implizite Referenzkonvertierung von 'DOC.Migrations.Configuration' in 'System.Data.Entity.DbContext' statt. DOC xxxxxxx\DOC\Migrations\Configuration.cs.
Wenn ich die Datei Configuration.cs überprüfe, hat sie sich geändert aus:
internal sealed class Configuration : DbMigrationsConfiguration
...zu:
internal sealed class Configuration : DbMigrationsConfiguration
... verursacht, dass das Projekt nicht erstellt werden kann
Das einzige Mal, dass ich es geschafft habe, funktioniert dies, indem das Entityframework von 6.1.3 auf 6.1.2 heruntergestuft und anschließend erneut aktualisiert wird.
Manchmal muss ich ein paar Mal upgraden und downgraden, VS schließen und erneut öffnen, dann funktioniert es.
Gibt es dafür eine Lösung? es ist sehr nervig.
Ich habe auch bemerkt, dass meine DbContext
name__-Klasse von IdentityDBContext
abgeleitet ist. Ist das in Ordnung? Ich weiß, dass Sie es normalerweise von DbContext
ableiten, aber da ich das Projekt mit dem Assistenten gestartet habe, wurde es automatisch erstellt und ich habe nur meine anderen Tabellen hinzugefügt.
Meine web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.Microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.Microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="data source=localhost\SQLTEST;initial catalog=DOC;User Id=xxx;Password=xxxx;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
<!--<add name="DefaultConnection" connectionString="data source=zzzzz;initial catalog=DOC;User Id=zzzzzz;Password=zzzzz;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<!--
For a description of web.config changes see http://go.Microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.2" />
</system.Web>
-->
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<modules>
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-Microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNet.Identity.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework.MappingAPI" publicKeyToken="7ee2e825d201459e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.1.0.9" newVersion="6.1.0.9" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Sie verwirren die Parameter für enable-migrations
und add-migration
.
enable-migrations
hat einen Kontexttypnamen. Sie geben den Konfigurationsnamen an, nicht den Kontext.
enable-migrations -ContextTypeName DOC.Models.ApplicationDbContext
Dann hinzufügen:
add-migration MyMigrationName -ConfigurationTypeName DOC.Migrations.Configuration
Ich bin nicht sicher, ob Sie überhaupt die Parameter benötigen, da es so aussieht, als hätten Sie ein einzelnes Projekt. Hier ist die Befehlsreferenz
Es ist nicht wichtig, dass Sie von IdentityDbContext erben. EF hat auch keine Version 6.3 und 6.4, es ist 6.1.3 oder EF Core.
Versuchen Sie, ein neues Projekt zu erstellen, um zu überprüfen, was wir brauchen. Ok so gehen Sie zur Datei> neues> Projekt, wählen Sie unter visuelles c # -Menü neue asp.net-Webanwendung einen beliebigen Namen für das Projekt, um nur zu überprüfen, was in Ihrem Projekt fehlt. Klicken Sie auf OK, wählen Sie MVC auf der linken Seite aus und auf der rechten Seite fehlt der Schritt. Sie können eine Schaltfläche zum Ändern der Authentifizierung sehen. Unter dieser Schaltfläche wird Authentifizierung: Keine Authentifizierung angezeigt. Klicken Sie dort und wählen Sie einzelne Benutzerkonten aus. Klicken Sie auf OK und dann auf diese Option, und installieren Sie Entität und Identität automatisch. Das ist das Problem. Ich hoffe, ich kann helfen, fühle mich frei, mich wieder zu kontaktieren.