Код: Выделить всё
public class Tariff
{
public int Id { get; set; }
public required string Name { get; set; }
public double MonthlyFee { get; set; }
public int NetworkSpeed { get; set; }
}
public class ApplicationUser : IdentityUser
{
// Added field and foreignkey attribute after, but that changed nothing
public int TariffId { get; set; }
[ForeignKey(nameof(TariffId))]
public required Tariff Tariff { get; set; }
public double Balance { get; set; }
}
public class ApplicationDbContext(DbContextOptions options) : IdentityDbContext(options)
{
public DbSet Tariff { get; set; }
}
Я также изменил процесс регистрации следующим образом:
Код: Выделить всё
var user = Activator.CreateInstance();
var defaultTariff = DbContext.Tariff.FirstOrDefault();
user.Tariff = defaultTariff!;
return user;
Код: Выделить всё
@page "/Account/Personal"
@using Microsoft.AspNetCore.Identity
@using WebApp.Components.Account.Shared
@using WebApp.Data
@inject UserManager UserManager
@inject SignInManager SignInManager
@inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager
@inject ApplicationDbContext DbContext
@foreach (var tariff in DbContext.Tariff.ToList())
{
@tariff.Name
}
@code {
private ApplicationUser user = default!;
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
user = await UserAccessor.GetRequiredUserAsync(HttpContext);
}
}
Чего мне не хватает для автоматического заполнения этого свойства?
Подробнее здесь: https://stackoverflow.com/questions/784 ... individual