4

I have the following packages installed:

  • "Microsoft.EntityFrameworkCore" 7.0.0
  • "Microsoft.EntityFrameworkCore.Design" 7.0.0
  • "MySql.EntityFrameworkCore" 7.0.0-preview5+MySQL8.0.31

I have my context file class:

namespace API.Context
{
    public class EventContext : DbContext
    {
        public EventContext(DbContextOptions<EventContext> options) : base(options)
        {
        }

        public DbSet<Property> Property { get; set; }

        public DbSet<Event> Event { get; set; }

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

            modelBuilder.Entity<Event>(entity =>
            {
                entity.HasKey(e => e.ID);
                entity.Property(e => e.Title).IsRequired();
            });

            modelBuilder.Entity<Property>(entity =>
            {
                entity.HasKey(e => e.ID);
                entity.Property(e => e.Key).IsRequired();
                entity.Property(e => e.Value).IsRequired();
                entity.HasOne(d => d.Event)
            .WithMany(p => p.Properties);
            });
        }
    }
}

And my Program.cs:

using API.Context;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContext<EventContext>(x => x.UseMySQL(builder.Configuration.GetConnectionString("DefaultConnection")));

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

My problem is that when I run the command:

dotnet ef database update

I get this error:

System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelInitializedConvention> Microsoft.EntityFrameworkCore.Metadata.Conventions.ConventionSet.get_ModelInitializedConventions()'.

What am I missing here?

1
  • Are you sure you use right nuget? - try Pomelo.EntityFrameworkCore.MySql 7.0.0-alpha.1. Commented Nov 16, 2022 at 20:16

1 Answer 1

6

I have the following packages installed:
...

  • "MySql.EntityFrameworkCore" 8.0.22

No, you don't, you have MySql.Data.EntityFrameworkCore, which is a legacy package which does not support .NET 7.

For .NET 7 support you need either install preview version of MySql.EntityFrameworkCore (latest - 7.0.0-preview5) or alpha version of Pomelo.EntityFrameworkCore.MySql (latest - 7.0.0-alpha.1)

UPD

Pomelo package was used.

The following versions of MySqlConnector, EF Core, .NET (Core), .NET Standard and .NET Framework are compatible with published releases of Pomelo.EntityFrameworkCore.MySql:

Release Branch MySqlConnector EF Core .NET (Core) .NET Standard .NET Framework
7.0.0-alpha.1 master >= 2.2.0 7.0.x 6.0+ - -
6.0.2 6.0-maint >= 2.1.2 6.0.x 6.0+ - -
5.0.4 5.0-maint >= 1.3.13 5.0.x 3.0+ 2.1 -
3.2.7 3.2-maint >= 0.69.10 < 1.0.0 3.1.x 2.0+ 2.0 4.6.1+
Sign up to request clarification or add additional context in comments.

7 Comments

You are correct. Now I am using the correct package, but I am just getting a different error :( I have updated the question.
@Neigaard the source of the issue can be the same - preview packages can have breaking changes, try downgrading other ef packages to preview 5 version.
@Neigaard I mean other EF Core packages.
@Neigaard I see two EF Core packages there. Try the Pomelo MySQL. Despite it being alpha, it was recently published, so potentially it is upgraded to the release version of EF Core.
Switched to Pomelo package worked
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.