1

Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation. it gives me this error

namespace DBStuff
{
    public class MessageDBContext : DbContext
    {
        public DbSet<Message> Messages { get; set; }

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

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Message>().ToTable("Messages");

            modelBuilder.Entity<Message>().HasKey(u => u.ID).HasName("PK_Messages");

            modelBuilder.Entity<Message>().HasIndex(p => p.Name).IsUnique().HasDatabaseName("Idx_Name");

            modelBuilder.Entity<Message>().Property(ug => ug.ID).HasColumnType("int").IsRequired();
            modelBuilder.Entity<Message>().Property(ug => ug.Name).HasColumnType("nvarchar(50)").IsRequired();
            modelBuilder.Entity<Message>().Property(ug => ug.Email).HasColumnType("nvarchar(50)").IsRequired(false);
            modelBuilder.Entity<Message>().Property(ug => ug.TelephoneNumber).HasColumnType("int").IsRequired();
            modelBuilder.Entity<Message>().Property(ug => ug._message).HasColumnType("nvarchar(200)").IsRequired();


        }
    }
}

Message Class:

namespace DBStuff
{
    public class Message
    {

        [Key]
        public int ID { get; set; }

        [Required]
        [MaxLength(50)]
        public string Name { get; set; }


        [MaxLength(25)]
        public string Email { get; set; }

        [Required]
        [MaxLength(15)]
        public int TelephoneNumber { get; set; }

        [Required]
        [MaxLength(150)]
        public string _message { get; set; }
    }
}

Startup.CS

namespace Somafix
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            //services.AddEntityFrameworkMySQL();
            services.AddDbContext<MessageDBContext>(options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

HomeController.cs

namespace Somafix.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly MessageDBContext _context;



        public HomeController(ILogger<HomeController> logger, MessageDBContext context)
        {
            _logger = logger;
            _context = context;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Catalog()
        {
            return View();
        }

        public IActionResult AboutUs()
        {
            return View();
        }



        //[HttpGet]
        //public IList<Message> Get()
        //{
        //    return (this._context.Messages.ToList());
        //}





        public IActionResult ContactUs()
        {
            return View();
        }


        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
5
  • 1
    Maybe you should try Pomelo.EntityFrameworkCore.MySql. Oracle's provider can be outdated and unstable. Commented Aug 11, 2021 at 11:28
  • 1
    Your target project 'Somafix' doesn't match your migrations assembly 'DBStuff'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Somafix")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project. Commented Aug 11, 2021 at 12:37
  • 1
    now this error ahah Commented Aug 11, 2021 at 12:37
  • 1
    my database is empty Commented Aug 11, 2021 at 12:38
  • SOLVED aaa :D yees Commented Aug 11, 2021 at 12:48

1 Answer 1

1

SOLVED GUYS YEAH!

so I changed the Nuget package . I was using mysql.data.entityframeworkcore and now I'm using pomelo.entityframeworkcore.mysql. I wrote in startup class this

services.AddDbContext(options => options.UseMySql(connectionString,ServerVersion.AutoDetect(connectionString), b=> b.MigrationsAssembly("Somafix"))); where Somafix is my asp mvc project , where the startup class is situated

Sign up to request clarification or add additional context in comments.

Comments

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.