Home > Mobile >  Trying to connect oracle database with my .NET Core MVC Project
Trying to connect oracle database with my .NET Core MVC Project

Time:10-11

I was trying to connect OracleDB to my .NET Core 6 MVC project. But I'm having an error while I'm trying to Migrate the model using add-migration Category. It shows build started and then succeeded. After that the error occurs:
Method not found: 'Void CoreTypeMappingParameters..ctor(System.Type, Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter, Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, System.Func`3<Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator>)'.

appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    //"DefaultConnection": "Server= TUMUL-DESTOP\\SQLEXPRESS;Database=Bulky;Trusted_Connection=True;TrustServerCertificate=True;"
    "DefaultConnection": "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={DESKTOP-1G0JV9U})(PORT={1521})))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME=XE))));User Id={SYSTEM};password={tiger}"
  }
}



ApplicationDBContext.cs:

using BulkyBooksWeb.Models;
using Microsoft.EntityFrameworkCore;

namespace BulkyBooksWeb.Data
{
    public class ApplicationDBContext : DbContext 
    {
        public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options):base(options)
        {

        }

        public DbSet<Category> Catagories { get; set; }
        public DbSet<User> Users { get; set; }
    }
}

Program.cs

using BulkyBooksWeb.Data;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
    builder.Services.AddControllersWithViews();
    builder.Services.AddDbContext<ApplicationDBContext>(options=>options.UseOracle(builder.Configuration.GetConnectionString("DefaultConnection")));




var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    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.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

I attached all the screenshots of my code below. Can anyone help me with where I'm doing things wrong?
ApplicationDBContext.cs
appsettings.json
Error
Nuget PM
Program.cs

CodePudding user response:

Try changing your nuget packages, this error can appear when your Entity Framework versions aren't matched up to the relevant EF package.

So in this case your oracle EF is v6, downgrade your Microsoft.EntityFramework packages to v6.

Hope that helps,

  • Related