Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

How to Updgrade MySql for EF core 1.1

My Original projects.json file is like following:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "MySql.Data.Core": "7.0.4-IR-191",
    "MySql.Data.EntityFrameworkCore": "7.0.6-IR31",
    "Swashbuckle": "6.0.0-beta902",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"

  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

These settings work with my MySql database. I wanted to upgrade EF core to 1.1 so that I could use Update() method in my repository like following (this is nice-one line code and I do not need to assign each attribute incoming object to original object):

  public void UpdateBook(long id, Book book)
  {  
     var originalBook=  _db.Books.FirstOrDefault(o => o.Id == id);
     _db.Entry(originalBook).CurrentValues.SetValues(book);
     _db.SaveChanges();
  }

However, when I upgraded EF core to 1.1 "Microsoft.EntityFrameworkCore": "1.0.0" my code started throwing error in startup.cs at these lines:

services.AddApplicationInsightsTelemetry(Configuration);
services.AddDbContext<WebAPIDataContext>(options =>
     {
            options.UseMySQL(Configuration.GetConnectionString("SampleConnection"));
            });

My guess is upgrading EF Core broke some dependency with MySql. Is it correct? How can I fix it?

UPDATE:

I removed "Microsoft.EntityFrameworkCore": "1.0.0" and "MySql.Data.Core": "7.0.4-IR-191" and replaced with "MySql.Data.EntityFrameworkCore": "6.10.1-beta". In my aspsettings.josn I have:

"ConnectionStrings": {
    "SampleConnection": "server=localhost;userid=root;pwd=root;port=3306;database=aspnet;sslmode=none;"
  },

After restoring packages I restarted visual studio and build the solution which threw me following error:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
"MySql.Data.Core": "7.0.4-IR-191",
"MySql.Data.EntityFrameworkCore": "7.0.6-IR31",

Both are outdated and Oracle fucked up versioning. See NuGet page.

The IR31 was the last version to support EF Core 1.0. IR-191 is even older and one of the 6.* was the first one to support EF Core 1.1.

Now there is again 7.0.7-m6 which also seems to support EF Core 1.1. Oracle seems to be playing rope skipping with the versions.

Either of the later two versions should work 6.10.1-beta or 7.0.7-m6.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...