Я использую Antdesign Blazor для своего проекта на сервере Asp.net Core bLazor.
Все было идеально, пока я не начал добавлять модели и интегрировать их с EntityFramework.Это мой Program.cs
using AntDesign.ProLayout;
using iMonitor5.Data;
using iMonitor5.Pages.Account;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddAntDesign();
//builder.Services.AddScoped(sp => new HttpClient
//{
// BaseAddress = new Uri(sp.GetService()!.BaseUri)
//});
builder.Services.Configure
(builder.Configuration.GetSection("ProSettings"));
builder.Services.AddInteractiveStringLocalizer();
builder.Services.AddLocalization();
//builder.Services.AddScoped();
//builder.Services.AddScoped();
//builder.Services.AddScoped();
//builder.Services.AddScoped();
//builder.Services.AddScoped();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies();
var connectionString = builder.Configuration.GetConnectionString("SQLiteDatabaseContext") ?? throw new InvalidOperationException("Connection string 'DatabaseContext' not found.");
builder.Services.AddDbContextFactory(options => {
options.UseSqlite(connectionString);
});
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentityCore(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores()
.AddSignInManager()
.AddDefaultTokenProviders();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService();
context.Database.EnsureCreated();
DbInitializer.Initialize(context);
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/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.MapBlazorHub();
//app.MapFallbackToPage("/_Host");
app.Run();
А это мой ApplicationDbContext:
using iMonitor5.Models.ActiveDirectory;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace iMonitor5.Data
{
public class ApplicationDbContext: IdentityDbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}
public DbSet ADDomains { get; set; }
public DbSet ADObjects { get; set; }
public DbSet ADEventTypes { get; set; }
public DbSet ADEvents { get; set; }
public DbSet ADChanges { get; set; }
public DbSet ADAuditLogs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity().ToTable(nameof(ADDomain));
modelBuilder.Entity().ToTable(nameof(ADObject));
modelBuilder.Entity().ToTable(nameof(ADEventType));
modelBuilder.Entity().ToTable(nameof(ADEvent));
modelBuilder.Entity().ToTable(nameof(ADChange));
modelBuilder.Entity().ToTable(nameof(ADAuditLog));
base.OnModelCreating(modelBuilder);
}
}
}
И ApplicationUser:
using Microsoft.AspNetCore.Identity;
namespace iMonitor5.Data
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
}
}
Я дважды проверил каждый класс, нет свойства с именем RenderFragment.
Это полная ошибка:< /p>
System.InvalidOperationException : 'No suitable constructor was found for entity type 'RenderFragment'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'object', 'method' in 'RenderFragment(object object, IntPtr method)'
Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound.'
Подробнее здесь: https://stackoverflow.com/questions/791 ... d-for-enti
Сервер Blazor с AntDesign Blazor — не найден подходящий конструктор для типа сущности «RenderFragment». ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как визуализировать компонент Blazor с помощью параметра RenderFragment со страницы Razor
Anonymous » » в форуме C# - 0 Ответы
- 34 Просмотры
-
Последнее сообщение Anonymous
-