EntityFrameworkCore MySql error in DotnetCore2.0 webapi

.net-core entity-framework-core mysql

Question

I Am working with EntityFrameworkCore MySql on a dotnetcore 2.0 api .

Here is the error I am getting

Unable to cast object of type 'ConcreteTypeMapping' to type 'Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping'.

I have been getting this error when trying to access any DbSet. I cannot track down if it is a mapping issue, connection issue or library issue. If anyone has seen this please let me know. Otherwise here is what I have so far.

public class GamerDbContext : DbContext
{
    public GamerDbContext()
    {

    }

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

    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<GamerModel>();
    }

    public DbSet<GamerModel> GamerModel { get; set; }
    //public DbSet<GamerProfileModel> GamerProfiles { get; set; }
}

public class GamerModel
{
    [Key]
    public int Id { get; set; }

    //[Column(TypeName = "VARCHAR")]
    //[StringLength(36)]
    public string Username { get; set; }

    //[Column(TypeName = "VARCHAR")]
    //[StringLength(1024)]
    public string Password { get; set; }

    //[NotMapped]
    //public List<GamerProfileModel> GamerProfiles { get; set; }
}
-- auto-generated definition
CREATE TABLE Gamers
(
   Id       INT AUTO_INCREMENT PRIMARY KEY,
   Username VARCHAR(36)   NOT NULL,
   Password VARCHAR(1024) NULL,
   CONSTRAINT Gamers_Id_uindex
   UNIQUE (Id),
   CONSTRAINT Gamers_Username_uindex
   UNIQUE (Username)
);
1
4
4/16/2018 6:37:15 PM

Accepted Answer

Figured it out.

It turns out I was referencing the nuget package Microsoft.EntityFrameworkCore Version 2.1.0-preview2-final. It seems that there is a compatibility issue with that and MySql.Data.EntityFrameworkCore. Once I removed the first package it worked fine.

6
4/16/2018 7:45:57 PM

Popular Answer

Setting all versions in NuGet Package Manager to the same worked for me.

enter image description here



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow