CS0311 C# Тип нельзя использовать в качестве параметра типа TContext в универсальном типе или методе. EntityFrameworkCorC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 CS0311 C# Тип нельзя использовать в качестве параметра типа TContext в универсальном типе или методе. EntityFrameworkCor

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»