无法从程序集“ Microsoft.EntityFrameworkCore”中加载类型“ Microsoft.EntityFrameworkCore.Metadata.Internal.IEntityMaterializer”

时间:2018-10-16 14:09:15

标签: c# ms-access asp.net-core asp.net-core-mvc

我试图将我的mvc核心应用程序大致连接到this guide之后连接到现有的ms访问数据库,但是在启动时遇到此错误:

  

TypeLoadException:无法从程序集“ Microsoft.EntityFrameworkCore,版本= 2.1.3.0,文化=中性,PublicKeyToken = adb9793829ddae60”中加载类型“ Microsoft.EntityFrameworkCore.Metadata.Internal.IEntityMaterializer”。

我真的很感谢任何指导,因为我有点迷茫,而且似乎没有太多关于这方面的信息

该应用程序现在非常简单,看起来像这样:

数据库

public class Database : DbContext
{
    public Database()
    {

    }

    public Database(DbContextOptions<Database> options)
        : base(options)
    {

    }

    public virtual DbSet<subQCItems> subQCItems { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            // warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
            // Provider=Microsoft.ACE.OLEDB.12.0;Data Source=W:\IT\Test\company.mdb
            optionsBuilder.UseJet(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=W:\IT\Test\company Backoffice.mdb");
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<subQCItems>(entity =>{
            entity.Property(e => e.Index).IsRequired();
            entity.Property(e => e.GRV).IsRequired();
        });
    }
}

subQCItems

public class subQCItems
{
    [Key]
    public int Index { get; set; }
    public int GRV { get; set; }
}

启动

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
    });

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    var connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=W:\IT\Test\company Backoffice.mdb";
    services.AddDbContext<Database>(options => options.UseJet(connection));
}

csproj

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="EntityFrameworkCore.Jet" Version="2.0.0" />
  <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

0 个答案:

没有答案