Yêu cầu Apr 10th, 2021 9:59 a.m. 158 0 0
  • 158 0 0
+1

Lỗi khi sử dụng Entity Framework Core để kết nối ASP.net với MySQL

Chia sẻ
  • 158 0 0

Chào mọi người, em đang học code ASP.net core 5.0 trên ubuntu với VS code và đang thử kết nối với MySQL thông qua EF core nhưng bị lỗi khi add new migration. Em đã thử kết nối với SQLserver và đã chạy được rồi. Đây là dòng thông báo lỗi:

Method 'Clone' in type 'MySql.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation. Có vẻ các phiên bản Entity em đang cài đặt đang không tương thích với nhau, nhưng em chưa biết update phiên bản nào cho phù hợp. Mong các cao nhân chỉ giáo ạ ^^! Item Group list:

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.14" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.14" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.tools" Version="2.1.14">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="6.10.4" />
  </ItemGroup>

Hàm configure services:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<BookStoreContext>(options =>
                options.UseMySQL("server=localhost;userid=root;password=;database=BookStore"));
            services.AddControllersWithViews();
            services.AddRazorPages().AddRazorRuntimeCompilation();
        }
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí