Ниже я получаю ошибку при выполнении: -
System.InvalidOperationException: невозможно создать DbSet для TenantInformation, потому что этот тип не включен в модель для контекста. в Microsoft.EntityFrameworkCore.Internal.InternalDbSet 1.get_EntityType()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet
1.CheckState () в Microsoft.EntityFrameworkCore.Internal.InternalDbSet 1.get_EntityQueryable()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet
1.System.Collections.Generi c .IEnumerable.GetEnumerator () в System.Collections c .List 1..ctor(IEnumerable
1) в System.Linq.Enumerable.ToList [TSource] (IEnumerable 1 source)
at Implementation.DataAccessImplementaion.RepositoryImplementation.TenantInformationRepository.GetTenantDetails() in C:\Users\Sumit\Documents\Sumit\MultiTenancy\Implementation\DataAccessImplementaion\RepositoryImplementation\TenantInformationRepository.cs:line 25
at Implementation.DataAccessImplementaion.UnitOfWorkImplementaion.TenantInformationUnitOfWork.GetTenantInformations() in C:\Users\Sumit\Documents\Sumit\MultiTenancy\Implementation\DataAccessImplementaion\UnitOfWorkImplementaion\TenantInformationUnitOfWork.cs:line 24
at MultiTenancy.Controllers.TenantsDetailsController.GetAllTenants() in C:\Users\Sumit\Documents\Sumit\MultiTenancy\MultiTenancy\Controllers\TenantsDetailsController.cs:line 37
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask
1 actionResultValueTask) в Microsoft.AspNetCore. Mvc .Infrastructure.ControllerActionInvoker.g__Awaited | 10_0 (ControllerActionInvok lastTask, State next, Scope scope, Object state, Boolean isCompleted) в Microsoft.AspNetCore. Mvc .Infrastructure.ControllerActionInvoker.Rethrow (ActionExecutedContextSealed context) в Microsoft.AspNetCore. Mvc .Infrastructure.ControllerActionInvoker.Ne Scope & scope, Object & state, Boolean & isCompleted) в Microsoft.AspNetCore. Mvc .Infrastructure.ControllerActionInvoker.g__Awaited | 13_0 (ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) в Microsoft.Asp NetCore. Mvc .Infrastructure.ResourceInvoker.g__Awaited | 19_0 (ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) в Microsoft.AspNetCore. invoker, Task task, IDisposable scope) в Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask | 6_0 (конечная точка конечной точки, задача requestTask, регистратор ILogger) в Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invokele context (HttpContextUser) в контексте SwaggerNet.Invoke .SwaggerUIMiddleware.Invoke (HttpContext httpContext) в Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke (HttpContext httpContext, ISwaggerProvider swaggerProvider) в Microsoft.AspNetCoredle.Diagnostics.DeveloperExceptionPageMusic 100Context * 100 * контекст: * this_context_context_context_context * -
public partial class GeneralCommonDBContext : DbContext ,IDbContextBase
{
public GeneralCommonDBContext()
{
}
public GeneralCommonDBContext(DbContextOptions<GeneralCommonDBContext> options)
: base(options)
{
}
public DbContext dbContext { get; set; }
public virtual DbSet<TenantInformation> TenantInformation { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TenantInformation>(entity =>
{
entity.HasKey(x => x.TenantId);
entity.Property(e => e.DataSource)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.InitialCatalog)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.Password).HasMaxLength(50);
entity.Property(e => e.TenantName)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.UserId).HasMaxLength(50);
});
// OnModelCreatingPartial(modelBuilder);
}
// partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
Это Код репозитория: -
public async Task<List<TenantInformation>> GetTenantDetails()
{
var tenantInformation = await Task.Run(() => Find(x => x.TenantId == 1).ToList());
return tenantInformation.ToList();
}
Это при запуске: -
services.AddDbContext (options => options.UseSqlServe r (Configuration.GetConnectionString ("GeneralCommonDataDBConnectionString")));