CS0311 C# Тип нельзя использовать в качестве параметра типа TContext в универсальном типе или методе. EntityFrameworkCor ⇐ C#
CS0311 C# Тип нельзя использовать в качестве параметра типа TContext в универсальном типе или методе. EntityFrameworkCor
I specify the context class I created in the entity project on the Startup.cs file and the connectionString data I created for connectionString. But why am I getting this error?
ERROR message: Severity Code Description Project File Line Suppression State Error CS0311 The type 'Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext' cannot be used as type parameter 'TContext' in the generic type or method 'EntityFrameworkServiceCollectionExtensions.AddDbContext(IServiceCollection, Action, ServiceLifetime, ServiceLifetime)'. There is no implicit reference conversion from 'Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext' to 'Microsoft.EntityFrameworkCore.DbContext'. EntityFramework2 C:\Users\xsamu\source\repos\EntityFramework2\EntityFramework2\Startup.cs 29 Active
Startup class:
namespace EntityFramework2 { 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.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection"))); } // 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?}"); }); } } } Entity configuration:
namespace EntityFramework2 { public class EntityConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasOne(navigationExpression: s => s.Name) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.DepartmentId); builder.HasOne(navigationExpression: s => s.TitleCode) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.TitleId); builder.HasOne(navigationExpression: s => s.PositionCode) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.PositionId); } } }
Источник: https://stackoverflow.com/questions/630 ... -the-gener
I specify the context class I created in the entity project on the Startup.cs file and the connectionString data I created for connectionString. But why am I getting this error?
ERROR message: Severity Code Description Project File Line Suppression State Error CS0311 The type 'Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext' cannot be used as type parameter 'TContext' in the generic type or method 'EntityFrameworkServiceCollectionExtensions.AddDbContext(IServiceCollection, Action, ServiceLifetime, ServiceLifetime)'. There is no implicit reference conversion from 'Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext' to 'Microsoft.EntityFrameworkCore.DbContext'. EntityFramework2 C:\Users\xsamu\source\repos\EntityFramework2\EntityFramework2\Startup.cs 29 Active
Startup class:
namespace EntityFramework2 { 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.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection"))); } // 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?}"); }); } } } Entity configuration:
namespace EntityFramework2 { public class EntityConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasOne(navigationExpression: s => s.Name) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.DepartmentId); builder.HasOne(navigationExpression: s => s.TitleCode) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.TitleId); builder.HasOne(navigationExpression: s => s.PositionCode) .WithOne(sa => sa.User) .HasForeignKey(sa => sa.PositionId); } } }
Источник: https://stackoverflow.com/questions/630 ... -the-gener
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Тип нельзя использовать в качестве параметра типа в универсальном типе или методе.
Anonymous » » в форуме C# - 0 Ответы
- 32 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Тип нельзя использовать в качестве параметра типа в универсальном типе или методе.
Anonymous » » в форуме C# - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Тип нельзя использовать в качестве параметра типа в универсальном типе или методе.
Anonymous » » в форуме C# - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-