2016-07-04 149 views
0

由於核心1.0 RTM的更新,我現在不能更新數據庫:實體框架的核心1.0 RTM添加遷移失敗

dotnet ef migrations add CreatedJobcards

現在我得到這個錯誤:

System.TypeLoadException: Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

我project.json看起來是這樣的:

{ 
    "webroot": "wwwroot", 
    "version": "1.0.0-*", 
    "dependencies": { 
    "Kendo.Mvc": "2016.2.630", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Identity": "1.0.0", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.0", 
    "Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.0", 
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.EntityFrameworkCore": "1.0.0", 
    "Microsoft.EntityFrameworkCore.Relational": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0", 
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final", 
    "Microsoft.Extensions.Configuration.Abstractions": "1.0.0", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", 
    "Microsoft.Extensions.DependencyInjection": "1.0.0", 
    "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0", 
    "Microsoft.Extensions.Logging": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0" 
    }, 
    "tools": { 
    "Microsoft.EntityFrameworkCore.Tools": { 
     "version": "1.0.0-preview1-final", 
     "imports": [ 
     "portable-net45+win8+dnxcore50", 
     "portable-net45+win8" 
     ] 
    } 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "version": "1.0.0", 
      "type": "platform" 
     } 
     } 
    } 
    }, 
    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "gcServer": true 
    }, 
    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "Views", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 
    "scripts": { 
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

UPDATE: 也發生在接下來的命令同樣的錯誤:

dotnet ef database update 0

dotnet ef migrations remove

更新2:包括數據庫內容檔案:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 
using Microsoft.EntityFrameworkCore; 
using mysite.com.Models; 
using Microsoft.EntityFrameworkCore.Metadata; 
using Microsoft.AspNetCore.Identity; 

namespace mysite.com.Data 
{ 
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser, Role, Guid> 
    { 

     protected override void OnModelCreating(ModelBuilder builder) 
     { 
      base.OnModelCreating(builder); 

      builder.Entity<ApplicationUser>(b => 
      { 
       b.Property(u => u.Id).HasColumnName("UserId").HasDefaultValueSql("newsequentialid()"); 
      }); 

      builder.Entity<Role>(b => 
      { 
       b.Property(u => u.Id).HasDefaultValueSql("newsequentialid()"); 
      }); 


      builder.Entity<Attachment>(entity => 
      { 
       entity.Property(e => e.AttachmentID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.AdminOnly).HasDefaultValueSql("0"); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.EntityName) 
        .IsRequired() 
        .HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Name) 
        .IsRequired() 
        .HasMaxLength(255); 
      }); 

      builder.Entity<Employee>(entity => 
      { 
       entity.Property(e => e.EmployeeID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.DateOfBirth).HasColumnType("date"); 

       entity.Property(e => e.EmployeeNumber).HasMaxLength(50); 

       entity.Property(e => e.ID_Passport_No).HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Name) 
        .IsRequired() 
        .HasMaxLength(255); 

       entity.Property(e => e.Position).HasMaxLength(255); 

       entity.Property(e => e.Status).HasMaxLength(255); 

       entity.Property(e => e.Surname).HasMaxLength(255); 

       entity.HasOne(d => d.Organisation) 
        .WithMany(p => p.Employee) 
        .HasForeignKey(d => d.OrganisationID) 
        .HasConstraintName("FK_Employee_Organisation"); 

       entity.HasOne(d => d.TestCycle) 
        .WithMany(p => p.Employee) 
        .HasForeignKey(d => d.TestCycleID) 
        .OnDelete(DeleteBehavior.SetNull) 
        .HasConstraintName("FK_Employee_TestCycle"); 
      }); 

      builder.Entity<Examiner>(entity => 
      { 
       entity.HasOne(a => a.User) 
       .WithMany(b => b.Examiners); 

       entity.Property(e => e.ExaminerID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.CompanyName).HasMaxLength(255); 

       entity.Property(e => e.CompanyTelephone).HasMaxLength(255); 

       entity.Property(e => e.CompanyURL).HasMaxLength(255); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Facebook).HasMaxLength(255); 

       entity.Property(e => e.FirstName).HasMaxLength(255); 

       entity.Property(e => e.Google).HasMaxLength(255); 

       entity.Property(e => e.Instagram).HasMaxLength(255); 

       entity.Property(e => e.LastName).HasMaxLength(255); 

       entity.Property(e => e.LinkedIn).HasMaxLength(255); 

       entity.Property(e => e.Mobile).HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Skype).HasMaxLength(255); 

       entity.Property(e => e.Status).HasMaxLength(255); 

       entity.Property(e => e.Twitter).HasMaxLength(255); 
      }); 

      builder.Entity<Note>(entity => 
      { 
       entity.Property(e => e.NoteID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.EntityName) 
        .IsRequired() 
        .HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.NoteText) 
        .IsRequired() 
        .HasColumnName("Note"); 
      }); 

      builder.Entity<Organisation>(entity => 
      { 
       entity.HasOne(a => a.User) 
       .WithMany(b => b.Organisations); 

       entity.Property(e => e.OrganisationID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.Branch).HasMaxLength(255); 

       entity.Property(e => e.BranchCode).HasMaxLength(255); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.GPSCoords).HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Name) 
        .IsRequired() 
        .HasMaxLength(255); 

       entity.Property(e => e.Status).HasMaxLength(50); 

       entity.Property(e => e.Telephone).HasMaxLength(255); 

       entity.Property(e => e.VATNo).HasMaxLength(255); 

       entity.Property(e => e.WebSite).HasMaxLength(255); 

      }); 

      builder.Entity<OrganisationContact>(entity => 
      { 
       entity.Property(e => e.OrganisationContactID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Email).HasMaxLength(255); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.Name).HasMaxLength(255); 

       entity.Property(e => e.Surname).HasMaxLength(255); 

       entity.Property(e => e.Telephone).HasMaxLength(255); 

       entity.Property(e => e.Type).HasColumnType("nchar(10)"); 

       entity.HasOne(d => d.Organisation) 
        .WithMany(p => p.OrganisationContact) 
        .HasForeignKey(d => d.OrganisationID) 
        .HasConstraintName("FK_OrganisationContact_Organisation"); 
      }); 

      builder.Entity<Polygraph>(entity => 
      { 
       entity.Property(e => e.PolygraphID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 


       entity.Property(e => e.CreatedOn).HasColumnType("datetime"); 

       entity.Property(e => e.ModifiedOn).HasColumnType("datetime"); 

       entity.Property(e => e.NextTestDate).HasColumnType("date"); 

       entity.Property(e => e.Place).HasMaxLength(255); 

       entity.Property(e => e.Reason).HasMaxLength(255); 

       entity.Property(e => e.Status).HasMaxLength(255); 

       entity.Property(e => e.TestResult).HasMaxLength(255); 

       entity.HasOne(d => d.Examiner) 
        .WithMany(p => p.Polygraph) 
        .HasForeignKey(d => d.ExaminerID) 

        .HasConstraintName("FK_Polygraph_Examiner"); 

       entity.HasOne(d => d.Employee) 
        .WithMany(p => p.Polygraph) 
        .HasForeignKey(d => d.EmployeeID) 
        .OnDelete(DeleteBehavior.SetNull) 
        .HasConstraintName("FK_Polygraph_Employee"); 

       entity.HasOne(d => d.PolygraphType) 
        .WithMany(p => p.Polygraph) 
        .HasForeignKey(d => d.PolygraphTypeID) 
        .OnDelete(DeleteBehavior.SetNull) 
        .HasConstraintName("FK_Polygraph_PolygraphType"); 
      }); 
      builder.Entity<Photo>(entity => 
      { 
       entity.Property(e => e.PhotoID) 
        .HasDefaultValueSql("newsequentialid()") 
        .ValueGeneratedOnAdd(); 
      }); 

      builder.Entity<TestCycle>(entity => 
      { 
       entity.Property(e => e.Description).HasMaxLength(maxLength: 255); 

       entity.Property(e => e.DisplayOrder).HasDefaultValueSql(sql: "0"); 
      }); 

      builder.Entity<PolygraphType>(entity => 
      { 
       entity.Property(e => e.PolygraphTypeID) 
        .UseSqlServerIdentityColumn() 
        .ValueGeneratedOnAdd(); 
      }); 

      builder.Entity<Jobcard>(entity => 
      { 
       entity.Property(e => e.JobcardID) 
        .HasDefaultValueSql(sql: "newsequentialid()") 
        .ValueGeneratedOnAdd(); 

       entity.Property(e => e.CreatedOn).HasColumnType(typeName: "datetime"); 

       entity.Property(e => e.BookingCount).IsRequired(required: true); 

       entity.Property(e => e.ModifiedOn).HasColumnType(typeName: "datetime"); 

       entity.Property(e => e.Reason).HasMaxLength(maxLength: 255); 

       entity.HasOne(d => d.Organisation) 
        .WithMany(p => p.Jobcards) 
        .HasForeignKey(d => d.OrganisationId) 
        .HasConstraintName(name: "FK_Jobcard_Organisation"); 

       entity.HasOne(d => d.Examiner) 
        .WithMany(p => p.Jobcards) 
        .HasForeignKey(d => d.ExaminerId) 
        .HasConstraintName(name: "FK_Jobcard_Examiner"); 
      }); 
      // Customize the ASP.NET Identity model and override the defaults if needed. 
      // For example, you can rename the ASP.NET Identity table names and more. 
      // Add your customizations after calling base.OnModelCreating(builder); 
     } 





     public virtual DbSet<Attachment> Attachment { get; set; } 
     public virtual DbSet<Employee> Employee { get; set; } 
     public virtual DbSet<Examiner> Examiner { get; set; } 
     public virtual DbSet<Note> Note { get; set; } 
     public virtual DbSet<Organisation> Organisation { get; set; } 
     public virtual DbSet<OrganisationContact> OrganisationContact { get; set; } 
     public virtual DbSet<Polygraph> Polygraph { get; set; } 
     public virtual DbSet<PolygraphType> PolygraphType { get; set; } 
     public virtual DbSet<TestCycle> TestCycle { get; set; } 
     public virtual DbSet<Photo> Photo { get; set; } 
     public virtual DbSet<Jobcard> Jobcard { get; set; } 
     public DbSet<ApplicationUser> ApplicationUser { get; set; } 
    } 
} 
+0

您能否顯示您的DbContext? –

+0

@VolkanSeçkinAkbayır我可以,但看到應用程序生成沒有問題,並且錯誤也發生在運行'dotnet ef數據庫更新0',我真的不認爲這是任何與** dbContext **。 然而,我將更新帖子,以包括那 – MerlinNZ

+0

所以,DbContext有通過構造注入的依賴? –

回答

1

由於您使用的版本1.0.0(而不是RC2)你的工具應該是preview2,而不是preview1。你也不需要imports了。當您修復project.json我會建議清洗的NuGet高速緩存與nuget.exe locals -Clear all 作爲一個側面說明 - 你必須publish-iis配置爲作爲postpublish腳本運行,但你沒有在你的項目這個工具,所以你會得到一個錯誤,當出版因爲dotnet將無法​​找到此工具。您需要將Microsoft.AspNetCore.IISIntegration.Tools添加到您的工具部分(再次preview2並且沒有imports