I am trying to connect my Web API build in asp.net 6 with MySql and I am having a lot of trouble
My Service looks like this
builder.Services.AddDbContext<TicketApiContext>(options =>
options.UseMySQL("CONNECTION_STRING"));
and my Database Context like this.
using Microsoft.EntityFrameworkCore;
namespace VelocityNetAPI.Data
{
public class TicketApiContext : DbContext
{
public TicketApiContext(DbContextOptions<TicketApiContext> options)
: base(options)
{
}
public DbSet<VelocityNetAPI.Models.Client> Client { get; set; }
public DbSet<VelocityNetAPI.Models.Job> Job { get; set; }
public DbSet<VelocityNetAPI.Models.User> User { get; set; }
public DbSet<VelocityNetAPI.Models.Dev> Dev { get; set; }
public DbSet<VelocityNetAPI.Models.FinishedJobs> FinishedJobs { get; set; }
}
}
when I run add-migration initial I get an error
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource'.
Any help will be very much appreciated.
Please help I am completely lost
Cheers All
2
Answers
So after tweaking I have the solution. Using the pomelo package and this line.
Hope this helps devs
I did an investigation into this here: https://bugs.mysql.com/bug.php?id=106592
Should be a workaround to it. It seems that in .NET6,
TryAddCoreServices()
was introduced but not implemented inMysql.EntityFrameworkCore
I’ve not heard much on if anybody has had any issue with this, but it worked for me.