using Enterprise.EmployeeManagement.DAL.Data;
using Enterprise.EmployeeManagement.Core.Services;
using Microsoft.EntityFrameworkCore;
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Microsoft.Extensions.Hosting;
using Pomelo.EntityFrameworkCore.MySql.Storage;
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// Configure Entity Framework to use MySQL with Pomelo and MySqlConnector
services.AddDbContext(options =>
options.UseMySql(
Configuration.GetConnectionString("DefaultConnection"),
new MySqlServerVersion(new Version(8, 0, 40))
)
);
// Register the UserService as scoped
services.AddScoped();
// Add controllers with views
services.AddControllersWithViews();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
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?}");
});
}
}
Следующие пакеты в редакторе отключены или выделены серым цветом:
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Pomelo.EntityFrameworkCore.MySql.Storage;
Я использую .NET Core 3.1 (строго ту же версию), Pomelo.EntityFrameworkCore.MySql 3.2.7
< li>Использование трехуровневой архитектуры с ядром, DAL и веб-уровнями (Startup.cs существует на веб-уровне)
Я пробовал делать следующие вещи:
Попробовал переустановить пакеты необходимой версии и убедился, что они находятся в разделе «Зависимости/Пакеты веб-слоя».
Я столкнулся с ошибкой: CS0246 в строке new MySqlServerVersion(new Version(8, 0, 40)) Ниже приведен мой Startup.cs: [code]using Enterprise.EmployeeManagement.DAL.Data; using Enterprise.EmployeeManagement.Core.Services; using Microsoft.EntityFrameworkCore; using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using Microsoft.Extensions.Hosting; using Pomelo.EntityFrameworkCore.MySql.Storage;
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services) { // Configure Entity Framework to use MySQL with Pomelo and MySqlConnector services.AddDbContext(options => options.UseMySql( Configuration.GetConnectionString("DefaultConnection"), new MySqlServerVersion(new Version(8, 0, 40)) ) );
// Register the UserService as scoped services.AddScoped();
// Add controllers with views services.AddControllersWithViews(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); 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?}"); }); } } [/code] Следующие пакеты в редакторе отключены или выделены серым цветом: [code]using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using Pomelo.EntityFrameworkCore.MySql.Storage; [/code] [list] [*]Я использую .NET Core 3.1 (строго ту же версию), Pomelo.EntityFrameworkCore.MySql 3.2.7 < li>Использование трехуровневой архитектуры с ядром, DAL и веб-уровнями (Startup.cs существует на веб-уровне) [/list] Я пробовал делать следующие вещи: [list] [*]Попробовал переустановить пакеты необходимой версии и убедился, что они находятся в разделе «Зависимости/Пакеты веб-слоя». [*]Попробовал очистить dotnet ,[code] dotnet build[/code] , восстановление dotnet несколько раз. [/list]