locked
Migration Issue with Npgsql.EntityFrameworkCore.PostgreSQL RRS feed

  • Question

  • User1461220549 posted

    Hi,

    I have following problem when I try to add a migration:

    Premises:

    I´m using Net.Core 5.0.0 preview 2

    Database PostgreSql last version

    Entity framework tools 5.0.0 preview 2

    Npgsql.EntityFrameworkCore.PostgreSQL 5.0.0 preview 2

    The error:

    I add first migration and it is done without problem

    The problem I get when I try to update-database and I get following:

    PM> add-migration initial
    Build started...
    Build succeeded.
    To undo this action, use Remove-Migration.
    PM> update-database
    Build started...
    Build succeeded.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.GetColumnType(String schema, String table, String name, ColumnOperation operation, IModel model)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.ColumnDefinition(String schema, String table, String name, ColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.ColumnDefinition(AddColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.CreateTableColumns(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder, Boolean terminate)
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.<>c.<.cctor>b__71_11(MigrationsSqlGenerator g, MigrationOperation o, IModel m, MigrationCommandListBuilder b)
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
       at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass15_2.<GetMigrationCommandLists>b__2()
       at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
       at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
    Object reference not set to an instance of an object.

    the migration is this:

    using System;
    using System.Collections.Generic;
    using FidaBlazor.Shared.Enums;
    using Microsoft.EntityFrameworkCore.Migrations;
    using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
    
    namespace FidaBlazor.Server.Migrations
    {
        public partial class initial : Migration
        {
            protected override void Up(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.CreateTable(
                    name: "AspNetRoles",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedName = table.Column<string>(maxLength: 256, nullable: true),
                        ConcurrencyStamp = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetRoles", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "BaseLangCodes",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        KeyText = table.Column<string>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_BaseLangCodes", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LanguageCodes",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Code = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LanguageCodes", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "Pages",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(nullable: false),
                        Url = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Pages", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetRoleClaims",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        RoleId = table.Column<int>(nullable: false),
                        ClaimType = table.Column<string>(nullable: true),
                        ClaimValue = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
                            column: x => x.RoleId,
                            principalTable: "AspNetRoles",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUsers",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserName = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
                        Email = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
                        EmailConfirmed = table.Column<bool>(nullable: false),
                        PasswordHash = table.Column<string>(nullable: true),
                        SecurityStamp = table.Column<string>(nullable: true),
                        ConcurrencyStamp = table.Column<string>(nullable: true),
                        PhoneNumber = table.Column<string>(nullable: true),
                        PhoneNumberConfirmed = table.Column<bool>(nullable: false),
                        TwoFactorEnabled = table.Column<bool>(nullable: false),
                        LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
                        LockoutEnabled = table.Column<bool>(nullable: false),
                        AccessFailedCount = table.Column<int>(nullable: false),
                        FirstName = table.Column<string>(maxLength: 64, nullable: true),
                        LastName = table.Column<string>(maxLength: 64, nullable: true),
                        BirthDate = table.Column<DateTime>(nullable: false),
                        PlaceOfBirth = table.Column<string>(nullable: true),
                        Gender = table.Column<int>(nullable: false),
                        Thumbnail = table.Column<string>(nullable: true),
                        PhotoUrl = table.Column<string>(nullable: true),
                        IsDisabled = table.Column<bool>(nullable: false),
                        LanguageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUsers", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetUsers_LanguageCodes_LanguageId",
                            column: x => x.LanguageId,
                            principalTable: "LanguageCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LangTranslations",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Translation = table.Column<string>(nullable: true),
                        BaseLangId = table.Column<int>(nullable: false),
                        LangCodeId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LangTranslations", x => x.Id);
                        table.ForeignKey(
                            name: "FK_LangTranslations_BaseLangCodes_BaseLangId",
                            column: x => x.BaseLangId,
                            principalTable: "BaseLangCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_LangTranslations_LanguageCodes_LangCodeId",
                            column: x => x.LangCodeId,
                            principalTable: "LanguageCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AppDynamicNavMenus",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Multi = table.Column<bool>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AppDynamicNavMenus", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_AppDynamicNavMenus_AspNetUsers_AppId",
                            column: x => x.AppId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserClaims",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserId = table.Column<int>(nullable: false),
                        ClaimType = table.Column<string>(nullable: true),
                        ClaimValue = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetUserClaims_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserLogins",
                    columns: table => new
                    {
                        LoginProvider = table.Column<string>(nullable: false),
                        ProviderKey = table.Column<string>(nullable: false),
                        ProviderDisplayName = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
                        table.ForeignKey(
                            name: "FK_AspNetUserLogins_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserRoles",
                    columns: table => new
                    {
                        UserId = table.Column<int>(nullable: false),
                        RoleId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
                        table.ForeignKey(
                            name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
                            column: x => x.RoleId,
                            principalTable: "AspNetRoles",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_AspNetUserRoles_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserTokens",
                    columns: table => new
                    {
                        UserId = table.Column<int>(nullable: false),
                        LoginProvider = table.Column<string>(nullable: false),
                        Name = table.Column<string>(nullable: false),
                        Value = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
                        table.ForeignKey(
                            name: "FK_AspNetUserTokens_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailMessages",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        References = table.Column<List<string>>(nullable: true),
                        MessageFlags = table.Column<List<EmailMessageFlag>>(nullable: true),
                        MessageId = table.Column<string>(nullable: true),
                        Date = table.Column<DateTimeOffset>(nullable: false),
                        Importance = table.Column<int>(nullable: false),
                        Priority = table.Column<int>(nullable: false),
                        Subject = table.Column<string>(nullable: true),
                        Body = table.Column<string>(nullable: true),
                        IsHtml = table.Column<bool>(nullable: false),
                        NeedReadReceipt = table.Column<bool>(nullable: false),
                        NeedDeliveredReceipt = table.Column<bool>(nullable: false),
                        InReplyTo = table.Column<string>(nullable: true),
                        MessageDirection = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailMessages", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailMessages_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailTemplates",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        ClassDataSource = table.Column<string>(nullable: true),
                        TemplateName = table.Column<string>(nullable: true),
                        Subject = table.Column<string>(nullable: true),
                        Body = table.Column<string>(nullable: true),
                        NeedReadReceipt = table.Column<bool>(nullable: false),
                        NeedDeliveredReceipt = table.Column<bool>(nullable: false),
                        Shared = table.Column<bool>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailTemplates", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailTemplates_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "OldPassword",
                    columns: table => new
                    {
                        id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        oldPasswordHash = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_OldPassword", x => x.id);
                        table.ForeignKey(
                            name: "FK_OldPassword_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "PhoneNumber",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        CountryDialCode = table.Column<string>(nullable: false),
                        Number = table.Column<string>(nullable: false),
                        NumberType = table.Column<int>(nullable: false),
                        Notes = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_PhoneNumber", x => x.Id);
                        table.ForeignKey(
                            name: "FK_PhoneNumber_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserAddress",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        NameId = table.Column<string>(nullable: false),
                        Street = table.Column<string>(nullable: false),
                        Number = table.Column<string>(nullable: false),
                        Flat = table.Column<string>(nullable: true),
                        Staircase = table.Column<string>(nullable: true),
                        City = table.Column<string>(nullable: false),
                        PostalCode = table.Column<string>(nullable: false),
                        County = table.Column<string>(nullable: false),
                        Country = table.Column<int>(nullable: false),
                        State = table.Column<string>(nullable: true),
                        AddressType = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserAddress", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserAddress_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserIdentityNumber",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        IdNumber = table.Column<string>(nullable: false),
                        IdType = table.Column<int>(nullable: false),
                        DocumentCopyUrl = table.Column<string>(nullable: true),
                        DocumentThumbnail = table.Column<string>(nullable: true),
                        IssuingDate = table.Column<DateTime>(nullable: false),
                        ExpiringDate = table.Column<DateTime>(nullable: false),
                        DocumentIssuer = table.Column<string>(nullable: true),
                        IssuingPlace = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserIdentityNumber", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserIdentityNumber_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserMailAddress",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(nullable: true),
                        Address = table.Column<string>(nullable: false),
                        MailType = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserMailAddress", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserMailAddress_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserProfile",
                    columns: table => new
                    {
                        Id = table.Column<long>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserId = table.Column<int>(nullable: false),
                        LastPageVisited = table.Column<string>(nullable: true),
                        IsNavOpen = table.Column<bool>(nullable: false),
                        IsNavMinified = table.Column<bool>(nullable: false),
                        Count = table.Column<int>(nullable: false),
                        LastUpdatedDate = table.Column<DateTime>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserProfile", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserProfile_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LangTransPage",
                    columns: table => new
                    {
                        langTranslationId = table.Column<int>(nullable: false),
                        PageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LangTransPage", x => new { x.PageId, x.langTranslationId });
                        table.ForeignKey(
                            name: "FK_LangTransPage_Pages_PageId",
                            column: x => x.PageId,
                            principalTable: "Pages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_LangTransPage_LangTranslations_langTranslationId",
                            column: x => x.langTranslationId,
                            principalTable: "LangTranslations",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailAdresses",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false),
                        Name = table.Column<string>(nullable: true),
                        Address = table.Column<string>(nullable: true),
                        ToEmailMessageId = table.Column<int>(nullable: false),
                        FromEmailMessageId = table.Column<int>(nullable: false),
                        CcEmailMessageId = table.Column<int>(nullable: false),
                        BccEmailMessageId = table.Column<int>(nullable: false),
                        ReplyEmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailAdresses", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_BccEmailMessageId",
                            column: x => x.BccEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_CcEmailMessageId",
                            column: x => x.CcEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_FromEmailMessageId",
                            column: x => x.FromEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_Id",
                            column: x => x.Id,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_ReplyEmailMessageId",
                            column: x => x.ReplyEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_ToEmailMessageId",
                            column: x => x.ToEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailHeaders",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Value = table.Column<string>(nullable: true),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailHeaders", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailHeaders_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailAttachnemts",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        FileName = table.Column<string>(nullable: true),
                        FileNameUrl = table.Column<string>(nullable: true),
                        FileFullPath = table.Column<string>(nullable: true),
                        FileUrl = table.Column<string>(nullable: true),
                        FileDataBytes = table.Column<byte[]>(nullable: true),
                        TemplateId = table.Column<int>(nullable: false),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailAttachnemts", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailAttachnemts_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAttachnemts_EmailTemplates_TemplateId",
                            column: x => x.TemplateId,
                            principalTable: "EmailTemplates",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "NavMenuItems",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Href = table.Column<string>(nullable: true),
                        Disabled = table.Column<bool>(nullable: false),
                        AllowSection = table.Column<bool>(nullable: false),
                        Content = table.Column<string>(nullable: true),
                        Icon = table.Column<string>(nullable: true),
                        AppDynamicNavMenuAppId = table.Column<int>(nullable: true),
                        SubMenuListAppId = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_NavMenuItems", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_NavMenuItems_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                            column: x => x.AppDynamicNavMenuAppId,
                            principalTable: "AppDynamicNavMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenus",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Selected = table.Column<bool>(nullable: false),
                        Expanded = table.Column<bool>(nullable: false),
                        AppDynamicNavMenuAppId = table.Column<int>(nullable: true),
                        SubMenuListAppId1 = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenus", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenus_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                            column: x => x.AppDynamicNavMenuAppId,
                            principalTable: "AppDynamicNavMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenuHeaders",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Content = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenuHeaders", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenuHeaders_SubMenus_AppId",
                            column: x => x.AppId,
                            principalTable: "SubMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenuLists",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenuLists", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenuLists_SubMenus_AppId",
                            column: x => x.AppId,
                            principalTable: "SubMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetRoleClaims_RoleId",
                    table: "AspNetRoleClaims",
                    column: "RoleId");
    
                migrationBuilder.CreateIndex(
                    name: "RoleNameIndex",
                    table: "AspNetRoles",
                    column: "NormalizedName",
                    unique: true);
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserClaims_UserId",
                    table: "AspNetUserClaims",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserLogins_UserId",
                    table: "AspNetUserLogins",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserRoles_RoleId",
                    table: "AspNetUserRoles",
                    column: "RoleId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUsers_LanguageId",
                    table: "AspNetUsers",
                    column: "LanguageId");
    
                migrationBuilder.CreateIndex(
                    name: "EmailIndex",
                    table: "AspNetUsers",
                    column: "NormalizedEmail");
    
                migrationBuilder.CreateIndex(
                    name: "UserNameIndex",
                    table: "AspNetUsers",
                    column: "NormalizedUserName",
                    unique: true);
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_BccEmailMessageId",
                    table: "EmailAdresses",
                    column: "BccEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_CcEmailMessageId",
                    table: "EmailAdresses",
                    column: "CcEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_FromEmailMessageId",
                    table: "EmailAdresses",
                    column: "FromEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_ReplyEmailMessageId",
                    table: "EmailAdresses",
                    column: "ReplyEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_ToEmailMessageId",
                    table: "EmailAdresses",
                    column: "ToEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAttachnemts_EmailMessageId",
                    table: "EmailAttachnemts",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAttachnemts_TemplateId",
                    table: "EmailAttachnemts",
                    column: "TemplateId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailHeaders_EmailMessageId",
                    table: "EmailHeaders",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailMessages_UserId",
                    table: "EmailMessages",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailTemplates_UserId",
                    table: "EmailTemplates",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTranslations_BaseLangId",
                    table: "LangTranslations",
                    column: "BaseLangId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTranslations_LangCodeId",
                    table: "LangTranslations",
                    column: "LangCodeId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTransPage_langTranslationId",
                    table: "LangTransPage",
                    column: "langTranslationId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_NavMenuItems_AppDynamicNavMenuAppId",
                    table: "NavMenuItems",
                    column: "AppDynamicNavMenuAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_NavMenuItems_SubMenuListAppId",
                    table: "NavMenuItems",
                    column: "SubMenuListAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_OldPassword_UserId",
                    table: "OldPassword",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_PhoneNumber_UserId",
                    table: "PhoneNumber",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_SubMenus_AppDynamicNavMenuAppId",
                    table: "SubMenus",
                    column: "AppDynamicNavMenuAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_SubMenus_SubMenuListAppId1",
                    table: "SubMenus",
                    column: "SubMenuListAppId1");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserAddress_UserId",
                    table: "UserAddress",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserIdentityNumber_UserId",
                    table: "UserIdentityNumber",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserMailAddress_UserId",
                    table: "UserMailAddress",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserProfile_UserId",
                    table: "UserProfile",
                    column: "UserId",
                    unique: true);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_NavMenuItems_SubMenuHeaders_AppId",
                    table: "NavMenuItems",
                    column: "AppId",
                    principalTable: "SubMenuHeaders",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Cascade);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_NavMenuItems_SubMenuLists_SubMenuListAppId",
                    table: "NavMenuItems",
                    column: "SubMenuListAppId",
                    principalTable: "SubMenuLists",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Restrict);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_SubMenus_SubMenuLists_SubMenuListAppId1",
                    table: "SubMenus",
                    column: "SubMenuListAppId1",
                    principalTable: "SubMenuLists",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Restrict);
            }
    
            protected override void Down(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.DropForeignKey(
                    name: "FK_AppDynamicNavMenus_AspNetUsers_AppId",
                    table: "AppDynamicNavMenus");
    
                migrationBuilder.DropForeignKey(
                    name: "FK_SubMenus_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                    table: "SubMenus");
    
                migrationBuilder.DropForeignKey(
                    name: "FK_SubMenus_SubMenuLists_SubMenuListAppId1",
                    table: "SubMenus");
    
                migrationBuilder.DropTable(
                    name: "AspNetRoleClaims");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserClaims");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserLogins");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserRoles");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserTokens");
    
                migrationBuilder.DropTable(
                    name: "EmailAdresses");
    
                migrationBuilder.DropTable(
                    name: "EmailAttachnemts");
    
                migrationBuilder.DropTable(
                    name: "EmailHeaders");
    
                migrationBuilder.DropTable(
                    name: "LangTransPage");
    
                migrationBuilder.DropTable(
                    name: "NavMenuItems");
    
                migrationBuilder.DropTable(
                    name: "OldPassword");
    
                migrationBuilder.DropTable(
                    name: "PhoneNumber");
    
                migrationBuilder.DropTable(
                    name: "UserAddress");
    
                migrationBuilder.DropTable(
                    name: "UserIdentityNumber");
    
                migrationBuilder.DropTable(
                    name: "UserMailAddress");
    
                migrationBuilder.DropTable(
                    name: "UserProfile");
    
                migrationBuilder.DropTable(
                    name: "AspNetRoles");
    
                migrationBuilder.DropTable(
                    name: "EmailTemplates");
    
                migrationBuilder.DropTable(
                    name: "EmailMessages");
    
                migrationBuilder.DropTable(
                    name: "Pages");
    
                migrationBuilder.DropTable(
                    name: "LangTranslations");
    
                migrationBuilder.DropTable(
                    name: "SubMenuHeaders");
    
                migrationBuilder.DropTable(
                    name: "BaseLangCodes");
    
                migrationBuilder.DropTable(
                    name: "AspNetUsers");
    
                migrationBuilder.DropTable(
                    name: "LanguageCodes");
    
                migrationBuilder.DropTable(
                    name: "AppDynamicNavMenus");
    
                migrationBuilder.DropTable(
                    name: "SubMenuLists");
    
                migrationBuilder.DropTable(
                    name: "SubMenus");
            }
        }
    }
    

    some tip ?

    Thank you in advance

    Wednesday, April 22, 2020 3:00 PM

All replies

  • User1461220549 posted

    Hi,

    I answer for my self because I found the error:

    The problem was that I inserted on one class a type of data that is non compatible with postgreSql like List<string> and List<EmailMessageFlag> that is a list of Enum.

    I fixed with creating a support class with each of that kind of properties.

    So now I can Migrate (and Update the Database) but now

    I have a new error on Remove-Migration:

    PM> add-migration Initial
    Build started...
    Build succeeded.
    To undo this action, use Remove-Migration.
    PM> remove-migration
    Build started...
    Build succeeded.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IProperty property, CoreTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(IProperty target, DiffContext diffContext, Boolean inline)+MoveNext()
       at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
       at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(ITable target, DiffContext diffContext)+MoveNext()
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
       at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
       at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IModel source, IModel target)
       at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
       at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0()
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
    Object reference not set to an instance of an object.

    Tanks for help

    Wednesday, April 22, 2020 3:46 PM
  • User711641945 posted

    Hi PiercarloBI,

    Could you share your model design and the DbContext?

    Best Regards,

    Rena

    Thursday, April 23, 2020 9:43 AM
  • User1461220549 posted

    Hello Rena,

    Here My DbContext:

    using FidaBlazor.Shared.Email;
    using FidaBlazor.Shared.Models.Account;
    using FidaBlazor.Shared.Models.Menus;
    using FidaBlazorUI_Share.Models;
    using FidaBlazorUI_Share.Models.Language;
    using Microsoft.AspNetCore.Identity;
    using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore;
    using System.Drawing.Printing;
    
    namespace FidaBlazor.Server.Data
    {
        public class DataContext : IdentityDbContext<User,
               Role, int, IdentityUserClaim<int>, UserRole, IdentityUserLogin<int>,
               IdentityRoleClaim<int>, IdentityUserToken<int>>
        {
            public DbSet<NavMenuItem> NavMenuItems { get; set; }
            public DbSet<SubMenu> SubMenus { get; set; }
            public DbSet<SubMenuHeader> SubMenuHeaders { get; set; }
            public DbSet<SubMenuList> SubMenuLists { get; set; }
            public DbSet<AppDynamicNavMenu> AppDynamicNavMenus { get; set; }
            public DbSet<BaseLangCode> BaseLangCodes { get; set; }
            public DbSet<LangTranslation> LangTranslations { get; set; }
            public DbSet<LanguageCode> LanguageCodes { get; set; }
            public DbSet<Page> Pages { get; set; }
            public DbSet<EmailMessage> EmailMessages {get; set;}
            public DbSet<EmailAddress> EmailAdresses { get; set; }
            public DbSet<EmailAttachment> EmailAttachments { get; set; }
            public DbSet<EmailHeader> EmailHeaders { get; set; }
            public DbSet<EmailTemplate> EmailTemplates { get; set; }
    
            public DataContext(DbContextOptions<DataContext> options) : base(options)
            {
            }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);
            }
    
            protected override void OnModelCreating(ModelBuilder builder)
            {
                base.OnModelCreating(builder);
    
                builder.Entity<UserRole>(userRole =>
                {
                    userRole.HasKey(ur => new { ur.UserId, ur.RoleId });
    
                    userRole.HasOne(ur => ur.Role)
                        .WithMany(r => r.UserRoles)
                        .HasForeignKey(ur => ur.RoleId)
                        .IsRequired();
    
                    userRole.HasOne(ur => ur.User)
                        .WithMany(r => r.UserRoles)
                        .HasForeignKey(ur => ur.UserId)
                        .IsRequired();
                });
    
                builder.Entity<LangTransPage>(langTransPage => {
    
                    langTransPage.HasKey(ltp => new { ltp.PageId, ltp.langTranslationId });
    
                    langTransPage
                        .HasOne(pg => pg.Page)
                        .WithMany(p => p.LangTransPages)
                        .HasForeignKey(fk => fk.PageId)
                        .IsRequired();
    
                    langTransPage
                        .HasOne(lt => lt.LangTranslation)
                        .WithMany(t => t.LangTransPages)
                        .HasForeignKey(fk => fk.langTranslationId)
                        .IsRequired();
                });
    
                builder.Entity<User>()
                    .HasOne(a => a.Profile)
                    .WithOne(b => b.ApplicationUser)
                    .HasForeignKey<UserProfile>(b => b.UserId);                
    
                builder.Entity<User>()
                    .HasOne(a => a.AppDynamicNavMenu)
                    .WithOne(b => b.ApplicationUser)
                    .HasForeignKey<AppDynamicNavMenu>(b => b.AppId)
                    .OnDelete(DeleteBehavior.Cascade);
    
                builder.Entity<User>()
                    .HasMany(u => u.Adresses)
                    .WithOne(a => a.User)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<User>()
                    .HasMany(u => u.SecondaryEMailAddresses)
                    .WithOne(a => a.User)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<User>()
                    .HasMany(u => u.PhoneNumbers)
                    .WithOne(a => a.User)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<User>()
                    .HasMany(u => u.IdentityNumbers)
                    .WithOne(a => a.User)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<User>()
                    .HasMany(u => u.EmailMessages)
                    .WithOne(em => em.User)
                    .IsRequired();
    
                builder.Entity<User>()
                    .HasMany(u => u.EmailTemplates)
                    .WithOne(em => em.User)
                    .IsRequired();
    
                builder.Entity<BaseLangCode>()
                    .HasMany(blc => blc.LangTranslations)
                    .WithOne(tl => tl.BaseLang)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<LanguageCode>()
                    .HasMany(lc => lc.LangTranslations)
                    .WithOne(tl => tl.LangCode)
                    .OnDelete(DeleteBehavior.Cascade)
                    .IsRequired();
    
                builder.Entity<SubMenuHeader>()
                    .HasOne(a => a.NavMenuItem)
                    .WithOne(b => b.SubMenuHeader)
                    .HasForeignKey<NavMenuItem>(b => b.AppId)
                    .OnDelete(DeleteBehavior.Cascade);
    
                builder.Entity<SubMenu>()
                    .HasOne(a => a.SubMenuHeader)
                    .WithOne(b => b.SubMenu)
                    .HasForeignKey<SubMenuHeader>(b => b.AppId)
                    .OnDelete(DeleteBehavior.Cascade);
    
                builder.Entity<SubMenu>()
                    .HasOne(a => a.SubMenuList)
                    .WithOne(b => b.SubMenu)
                    .HasForeignKey<SubMenuList>(b => b.AppId)
                    .OnDelete(DeleteBehavior.Cascade);
    
                builder.Entity<EmailTemplate>()
                    .HasMany(et => et.Attachments)
                    .WithOne(at => at.Template)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.Attachments)
                    .WithOne(at => at.EmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.FromAddresses)
                    .WithOne(fa => fa.FromEmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.CcAddresses)
                    .WithOne(fa => fa.CcEmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.BccAddresses)
                    .WithOne(fa => fa.BccEmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.ToAddresses)
                    .WithOne(fa => fa.ToEmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.ReplyTo)
                    .WithOne(fa => fa.ReplyEmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.Headers)
                    .WithOne(he => he.EmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.MessageFlags)
                    .WithOne(he => he.EmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasMany(em => em.References)
                    .WithOne(he => he.EmailMessage)
                    .IsRequired();
    
                builder.Entity<EmailMessage>()
                    .HasOne(em => em.Sender)
                    .WithOne(he => he.SenderEmailMessage)
                    .HasForeignKey<EmailAddress>(ea => ea.Id)
                    .IsRequired();
    
            }
        }
    }
    

    The Initial Migration:

    using System;
    using Microsoft.EntityFrameworkCore.Migrations;
    using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
    
    namespace FidaBlazor.Server.Migrations
    {
        public partial class Initial : Migration
        {
            protected override void Up(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.CreateTable(
                    name: "AspNetRoles",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedName = table.Column<string>(maxLength: 256, nullable: true),
                        ConcurrencyStamp = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetRoles", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "BaseLangCodes",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        KeyText = table.Column<string>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_BaseLangCodes", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LanguageCodes",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Code = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LanguageCodes", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "Pages",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(nullable: false),
                        Url = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Pages", x => x.Id);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetRoleClaims",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        RoleId = table.Column<int>(nullable: false),
                        ClaimType = table.Column<string>(nullable: true),
                        ClaimValue = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
                            column: x => x.RoleId,
                            principalTable: "AspNetRoles",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUsers",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserName = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
                        Email = table.Column<string>(maxLength: 256, nullable: true),
                        NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
                        EmailConfirmed = table.Column<bool>(nullable: false),
                        PasswordHash = table.Column<string>(nullable: true),
                        SecurityStamp = table.Column<string>(nullable: true),
                        ConcurrencyStamp = table.Column<string>(nullable: true),
                        PhoneNumber = table.Column<string>(nullable: true),
                        PhoneNumberConfirmed = table.Column<bool>(nullable: false),
                        TwoFactorEnabled = table.Column<bool>(nullable: false),
                        LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
                        LockoutEnabled = table.Column<bool>(nullable: false),
                        AccessFailedCount = table.Column<int>(nullable: false),
                        FirstName = table.Column<string>(maxLength: 64, nullable: true),
                        LastName = table.Column<string>(maxLength: 64, nullable: true),
                        BirthDate = table.Column<DateTime>(nullable: false),
                        PlaceOfBirth = table.Column<string>(nullable: true),
                        Gender = table.Column<int>(nullable: false),
                        Thumbnail = table.Column<string>(nullable: true),
                        PhotoUrl = table.Column<string>(nullable: true),
                        IsDisabled = table.Column<bool>(nullable: false),
                        LanguageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUsers", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetUsers_LanguageCodes_LanguageId",
                            column: x => x.LanguageId,
                            principalTable: "LanguageCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LangTranslations",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Translation = table.Column<string>(nullable: true),
                        BaseLangId = table.Column<int>(nullable: false),
                        LangCodeId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LangTranslations", x => x.Id);
                        table.ForeignKey(
                            name: "FK_LangTranslations_BaseLangCodes_BaseLangId",
                            column: x => x.BaseLangId,
                            principalTable: "BaseLangCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_LangTranslations_LanguageCodes_LangCodeId",
                            column: x => x.LangCodeId,
                            principalTable: "LanguageCodes",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AppDynamicNavMenus",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Multi = table.Column<bool>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AppDynamicNavMenus", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_AppDynamicNavMenus_AspNetUsers_AppId",
                            column: x => x.AppId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserClaims",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserId = table.Column<int>(nullable: false),
                        ClaimType = table.Column<string>(nullable: true),
                        ClaimValue = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AspNetUserClaims_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserLogins",
                    columns: table => new
                    {
                        LoginProvider = table.Column<string>(nullable: false),
                        ProviderKey = table.Column<string>(nullable: false),
                        ProviderDisplayName = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
                        table.ForeignKey(
                            name: "FK_AspNetUserLogins_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserRoles",
                    columns: table => new
                    {
                        UserId = table.Column<int>(nullable: false),
                        RoleId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
                        table.ForeignKey(
                            name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
                            column: x => x.RoleId,
                            principalTable: "AspNetRoles",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_AspNetUserRoles_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "AspNetUserTokens",
                    columns: table => new
                    {
                        UserId = table.Column<int>(nullable: false),
                        LoginProvider = table.Column<string>(nullable: false),
                        Name = table.Column<string>(nullable: false),
                        Value = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
                        table.ForeignKey(
                            name: "FK_AspNetUserTokens_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailMessages",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        MessageId = table.Column<string>(nullable: true),
                        Date = table.Column<DateTimeOffset>(nullable: false),
                        Importance = table.Column<int>(nullable: false),
                        Priority = table.Column<int>(nullable: false),
                        Subject = table.Column<string>(nullable: true),
                        Body = table.Column<string>(nullable: true),
                        IsHtml = table.Column<bool>(nullable: false),
                        NeedReadReceipt = table.Column<bool>(nullable: false),
                        NeedDeliveredReceipt = table.Column<bool>(nullable: false),
                        InReplyTo = table.Column<string>(nullable: true),
                        MessageDirection = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailMessages", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailMessages_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailTemplates",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        ClassDataSource = table.Column<string>(nullable: true),
                        TemplateName = table.Column<string>(nullable: true),
                        Subject = table.Column<string>(nullable: true),
                        Body = table.Column<string>(nullable: true),
                        NeedReadReceipt = table.Column<bool>(nullable: false),
                        NeedDeliveredReceipt = table.Column<bool>(nullable: false),
                        Shared = table.Column<bool>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailTemplates", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailTemplates_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "OldPassword",
                    columns: table => new
                    {
                        id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        oldPasswordHash = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_OldPassword", x => x.id);
                        table.ForeignKey(
                            name: "FK_OldPassword_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "PhoneNumber",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        CountryDialCode = table.Column<string>(nullable: false),
                        Number = table.Column<string>(nullable: false),
                        NumberType = table.Column<int>(nullable: false),
                        Notes = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_PhoneNumber", x => x.Id);
                        table.ForeignKey(
                            name: "FK_PhoneNumber_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserAddress",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        NameId = table.Column<string>(nullable: false),
                        Street = table.Column<string>(nullable: false),
                        Number = table.Column<string>(nullable: false),
                        Flat = table.Column<string>(nullable: true),
                        Staircase = table.Column<string>(nullable: true),
                        City = table.Column<string>(nullable: false),
                        PostalCode = table.Column<string>(nullable: false),
                        County = table.Column<string>(nullable: false),
                        Country = table.Column<int>(nullable: false),
                        State = table.Column<string>(nullable: true),
                        AddressType = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserAddress", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserAddress_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserIdentityNumber",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        IdNumber = table.Column<string>(nullable: false),
                        IdType = table.Column<int>(nullable: false),
                        DocumentCopyUrl = table.Column<string>(nullable: true),
                        DocumentThumbnail = table.Column<string>(nullable: true),
                        IssuingDate = table.Column<DateTime>(nullable: false),
                        ExpiringDate = table.Column<DateTime>(nullable: false),
                        DocumentIssuer = table.Column<string>(nullable: true),
                        IssuingPlace = table.Column<string>(nullable: true),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserIdentityNumber", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserIdentityNumber_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserMailAddress",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Name = table.Column<string>(nullable: true),
                        Address = table.Column<string>(nullable: false),
                        MailType = table.Column<int>(nullable: false),
                        UserId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserMailAddress", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserMailAddress_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "UserProfile",
                    columns: table => new
                    {
                        Id = table.Column<long>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        UserId = table.Column<int>(nullable: false),
                        LastPageVisited = table.Column<string>(nullable: true),
                        IsNavOpen = table.Column<bool>(nullable: false),
                        IsNavMinified = table.Column<bool>(nullable: false),
                        Count = table.Column<int>(nullable: false),
                        LastUpdatedDate = table.Column<DateTime>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_UserProfile", x => x.Id);
                        table.ForeignKey(
                            name: "FK_UserProfile_AspNetUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AspNetUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "LangTransPage",
                    columns: table => new
                    {
                        langTranslationId = table.Column<int>(nullable: false),
                        PageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_LangTransPage", x => new { x.PageId, x.langTranslationId });
                        table.ForeignKey(
                            name: "FK_LangTransPage_Pages_PageId",
                            column: x => x.PageId,
                            principalTable: "Pages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_LangTransPage_LangTranslations_langTranslationId",
                            column: x => x.langTranslationId,
                            principalTable: "LangTranslations",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailAdresses",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false),
                        Name = table.Column<string>(nullable: true),
                        Address = table.Column<string>(nullable: true),
                        ToEmailMessageId = table.Column<int>(nullable: false),
                        FromEmailMessageId = table.Column<int>(nullable: false),
                        CcEmailMessageId = table.Column<int>(nullable: false),
                        BccEmailMessageId = table.Column<int>(nullable: false),
                        ReplyEmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailAdresses", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_BccEmailMessageId",
                            column: x => x.BccEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_CcEmailMessageId",
                            column: x => x.CcEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_FromEmailMessageId",
                            column: x => x.FromEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_Id",
                            column: x => x.Id,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_ReplyEmailMessageId",
                            column: x => x.ReplyEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAdresses_EmailMessages_ToEmailMessageId",
                            column: x => x.ToEmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailHeaders",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Value = table.Column<string>(nullable: true),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailHeaders", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailHeaders_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailMessageFlag",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        MessageFlag = table.Column<int>(nullable: false),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailMessageFlag", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailMessageFlag_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailMessageId",
                    columns: table => new
                    {
                        Id = table.Column<string>(nullable: false),
                        MessageId = table.Column<string>(nullable: true),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailMessageId", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailMessageId_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "EmailAttachments",
                    columns: table => new
                    {
                        Id = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        FileName = table.Column<string>(nullable: true),
                        FileNameUrl = table.Column<string>(nullable: true),
                        FileFullPath = table.Column<string>(nullable: true),
                        FileUrl = table.Column<string>(nullable: true),
                        FileDataBytes = table.Column<byte[]>(nullable: true),
                        TemplateId = table.Column<int>(nullable: false),
                        EmailMessageId = table.Column<int>(nullable: false)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_EmailAttachments", x => x.Id);
                        table.ForeignKey(
                            name: "FK_EmailAttachments_EmailMessages_EmailMessageId",
                            column: x => x.EmailMessageId,
                            principalTable: "EmailMessages",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                        table.ForeignKey(
                            name: "FK_EmailAttachments_EmailTemplates_TemplateId",
                            column: x => x.TemplateId,
                            principalTable: "EmailTemplates",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "NavMenuItems",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Href = table.Column<string>(nullable: true),
                        Disabled = table.Column<bool>(nullable: false),
                        AllowSection = table.Column<bool>(nullable: false),
                        Content = table.Column<string>(nullable: true),
                        Icon = table.Column<string>(nullable: true),
                        AppDynamicNavMenuAppId = table.Column<int>(nullable: true),
                        SubMenuListAppId = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_NavMenuItems", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_NavMenuItems_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                            column: x => x.AppDynamicNavMenuAppId,
                            principalTable: "AppDynamicNavMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenus",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false)
                            .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Selected = table.Column<bool>(nullable: false),
                        Expanded = table.Column<bool>(nullable: false),
                        AppDynamicNavMenuAppId = table.Column<int>(nullable: true),
                        SubMenuListAppId1 = table.Column<int>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenus", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenus_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                            column: x => x.AppDynamicNavMenuAppId,
                            principalTable: "AppDynamicNavMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Restrict);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenuHeaders",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true),
                        Content = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenuHeaders", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenuHeaders_SubMenus_AppId",
                            column: x => x.AppId,
                            principalTable: "SubMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateTable(
                    name: "SubMenuLists",
                    columns: table => new
                    {
                        AppId = table.Column<int>(nullable: false),
                        Id = table.Column<string>(nullable: true),
                        Description = table.Column<string>(nullable: true),
                        Class = table.Column<string>(nullable: true),
                        Style = table.Column<string>(nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_SubMenuLists", x => x.AppId);
                        table.ForeignKey(
                            name: "FK_SubMenuLists_SubMenus_AppId",
                            column: x => x.AppId,
                            principalTable: "SubMenus",
                            principalColumn: "AppId",
                            onDelete: ReferentialAction.Cascade);
                    });
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetRoleClaims_RoleId",
                    table: "AspNetRoleClaims",
                    column: "RoleId");
    
                migrationBuilder.CreateIndex(
                    name: "RoleNameIndex",
                    table: "AspNetRoles",
                    column: "NormalizedName",
                    unique: true);
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserClaims_UserId",
                    table: "AspNetUserClaims",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserLogins_UserId",
                    table: "AspNetUserLogins",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUserRoles_RoleId",
                    table: "AspNetUserRoles",
                    column: "RoleId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_AspNetUsers_LanguageId",
                    table: "AspNetUsers",
                    column: "LanguageId");
    
                migrationBuilder.CreateIndex(
                    name: "EmailIndex",
                    table: "AspNetUsers",
                    column: "NormalizedEmail");
    
                migrationBuilder.CreateIndex(
                    name: "UserNameIndex",
                    table: "AspNetUsers",
                    column: "NormalizedUserName",
                    unique: true);
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_BccEmailMessageId",
                    table: "EmailAdresses",
                    column: "BccEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_CcEmailMessageId",
                    table: "EmailAdresses",
                    column: "CcEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_FromEmailMessageId",
                    table: "EmailAdresses",
                    column: "FromEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_ReplyEmailMessageId",
                    table: "EmailAdresses",
                    column: "ReplyEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAdresses_ToEmailMessageId",
                    table: "EmailAdresses",
                    column: "ToEmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAttachments_EmailMessageId",
                    table: "EmailAttachments",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailAttachments_TemplateId",
                    table: "EmailAttachments",
                    column: "TemplateId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailHeaders_EmailMessageId",
                    table: "EmailHeaders",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailMessageFlag_EmailMessageId",
                    table: "EmailMessageFlag",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailMessageId_EmailMessageId",
                    table: "EmailMessageId",
                    column: "EmailMessageId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailMessages_UserId",
                    table: "EmailMessages",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_EmailTemplates_UserId",
                    table: "EmailTemplates",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTranslations_BaseLangId",
                    table: "LangTranslations",
                    column: "BaseLangId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTranslations_LangCodeId",
                    table: "LangTranslations",
                    column: "LangCodeId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_LangTransPage_langTranslationId",
                    table: "LangTransPage",
                    column: "langTranslationId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_NavMenuItems_AppDynamicNavMenuAppId",
                    table: "NavMenuItems",
                    column: "AppDynamicNavMenuAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_NavMenuItems_SubMenuListAppId",
                    table: "NavMenuItems",
                    column: "SubMenuListAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_OldPassword_UserId",
                    table: "OldPassword",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_PhoneNumber_UserId",
                    table: "PhoneNumber",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_SubMenus_AppDynamicNavMenuAppId",
                    table: "SubMenus",
                    column: "AppDynamicNavMenuAppId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_SubMenus_SubMenuListAppId1",
                    table: "SubMenus",
                    column: "SubMenuListAppId1");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserAddress_UserId",
                    table: "UserAddress",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserIdentityNumber_UserId",
                    table: "UserIdentityNumber",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserMailAddress_UserId",
                    table: "UserMailAddress",
                    column: "UserId");
    
                migrationBuilder.CreateIndex(
                    name: "IX_UserProfile_UserId",
                    table: "UserProfile",
                    column: "UserId",
                    unique: true);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_NavMenuItems_SubMenuHeaders_AppId",
                    table: "NavMenuItems",
                    column: "AppId",
                    principalTable: "SubMenuHeaders",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Cascade);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_NavMenuItems_SubMenuLists_SubMenuListAppId",
                    table: "NavMenuItems",
                    column: "SubMenuListAppId",
                    principalTable: "SubMenuLists",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Restrict);
    
                migrationBuilder.AddForeignKey(
                    name: "FK_SubMenus_SubMenuLists_SubMenuListAppId1",
                    table: "SubMenus",
                    column: "SubMenuListAppId1",
                    principalTable: "SubMenuLists",
                    principalColumn: "AppId",
                    onDelete: ReferentialAction.Restrict);
            }
    
            protected override void Down(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.DropForeignKey(
                    name: "FK_AppDynamicNavMenus_AspNetUsers_AppId",
                    table: "AppDynamicNavMenus");
    
                migrationBuilder.DropForeignKey(
                    name: "FK_SubMenus_AppDynamicNavMenus_AppDynamicNavMenuAppId",
                    table: "SubMenus");
    
                migrationBuilder.DropForeignKey(
                    name: "FK_SubMenus_SubMenuLists_SubMenuListAppId1",
                    table: "SubMenus");
    
                migrationBuilder.DropTable(
                    name: "AspNetRoleClaims");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserClaims");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserLogins");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserRoles");
    
                migrationBuilder.DropTable(
                    name: "AspNetUserTokens");
    
                migrationBuilder.DropTable(
                    name: "EmailAdresses");
    
                migrationBuilder.DropTable(
                    name: "EmailAttachments");
    
                migrationBuilder.DropTable(
                    name: "EmailHeaders");
    
                migrationBuilder.DropTable(
                    name: "EmailMessageFlag");
    
                migrationBuilder.DropTable(
                    name: "EmailMessageId");
    
                migrationBuilder.DropTable(
                    name: "LangTransPage");
    
                migrationBuilder.DropTable(
                    name: "NavMenuItems");
    
                migrationBuilder.DropTable(
                    name: "OldPassword");
    
                migrationBuilder.DropTable(
                    name: "PhoneNumber");
    
                migrationBuilder.DropTable(
                    name: "UserAddress");
    
                migrationBuilder.DropTable(
                    name: "UserIdentityNumber");
    
                migrationBuilder.DropTable(
                    name: "UserMailAddress");
    
                migrationBuilder.DropTable(
                    name: "UserProfile");
    
                migrationBuilder.DropTable(
                    name: "AspNetRoles");
    
                migrationBuilder.DropTable(
                    name: "EmailTemplates");
    
                migrationBuilder.DropTable(
                    name: "EmailMessages");
    
                migrationBuilder.DropTable(
                    name: "Pages");
    
                migrationBuilder.DropTable(
                    name: "LangTranslations");
    
                migrationBuilder.DropTable(
                    name: "SubMenuHeaders");
    
                migrationBuilder.DropTable(
                    name: "BaseLangCodes");
    
                migrationBuilder.DropTable(
                    name: "AspNetUsers");
    
                migrationBuilder.DropTable(
                    name: "LanguageCodes");
    
                migrationBuilder.DropTable(
                    name: "AppDynamicNavMenus");
    
                migrationBuilder.DropTable(
                    name: "SubMenuLists");
    
                migrationBuilder.DropTable(
                    name: "SubMenus");
            }
        }
    }
    

    The Last Migration:

    using Microsoft.EntityFrameworkCore.Migrations;
    
    namespace FidaBlazor.Server.Migrations
    {
        public partial class EmailMessage_User_Amended : Migration
        {
            protected override void Up(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.AddColumn<long>(
                    name: "Uid",
                    table: "EmailMessages",
                    nullable: false,
                    defaultValue: 0L);
    
                migrationBuilder.AddColumn<string>(
                    name: "ImapPassword",
                    table: "AspNetUsers",
                    nullable: true);
            }
    
            protected override void Down(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.DropColumn(
                    name: "Uid",
                    table: "EmailMessages");
    
                migrationBuilder.DropColumn(
                    name: "ImapPassword",
                    table: "AspNetUsers");
            }
        }
    }
    

    The Models:

    using FidaBlazor.Shared.Email;
    using FidaBlazor.Shared.Enums;
    using FidaBlazor.Shared.Models.Account.Login;
    using FidaBlazor.Shared.Models.Menus;
    using FidaBlazorUI_Share.Models.Language;
    using Microsoft.AspNetCore.Identity;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class User : IdentityUser<int>
        {
            [MaxLength(64)]
            public string FirstName { get; set; }
            [MaxLength(64)]
            public string LastName { get; set; }
            public UserProfile Profile { get; set; }
            public DateTime BirthDate { get; set; }
            public string PlaceOfBirth { get; set; }
            public Gender Gender { get; set; }
            public string Thumbnail { get; set; }
            public string PhotoUrl { get; set; }
            public bool IsDisabled { get; set; }
            public string ImapPassword { get; set; }
            [Required]
            public LanguageCode Language { get; set; }
            public AppDynamicNavMenu AppDynamicNavMenu { get; set; }
            public List<UserMailAddress> SecondaryEMailAddresses { get; set; }
            public List<UserAddress> Adresses { get; set; }
            public List<PhoneNumber> PhoneNumbers { get; set; }
            public List<UserIdentityNumber> IdentityNumbers { get; set; }
            public ICollection<UserRole> UserRoles { get; set; }
            public List<OldPassword> oldPasswords { get; set; }
            public List<EmailMessage> EmailMessages { get; set; }
            public List<EmailTemplate> EmailTemplates { get; set; }
        }
    }
    
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazorUI_Share.Models.Language
    {
        public class BaseLangCode
        {
            [Key]
            public int Id { get; set; }
            [Required]
            public string KeyText { get; set; }
    
            public List<LangTranslation> LangTranslations { get; set; }
    
        }
    }
    using System.Collections.Generic;
    
    namespace FidaBlazorUI_Share.Models.Language
    {
        public class LangTranslation
        {
            public int Id { get; set; }
            public string Translation { get; set; }
    
            public BaseLangCode BaseLang { get; set; }
            public LanguageCode LangCode { get; set; }
    
            public List<LangTransPage> LangTransPages { get; set; }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace FidaBlazorUI_Share.Models.Language
    {
        public class LangTransPage
        {
            public int langTranslationId { get; set; }
            public int PageId { get; set; }
            public LangTranslation LangTranslation { get; set; }
            public Page Page { get; set; }
        }
    }
    
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazorUI_Share.Models.Language
    {
        public class LanguageCode
        {
            [Key]
            public int Id { get; set; }
            public string Code { get; set; }
            public string Description { get; set; }
    
            public List<LangTranslation> LangTranslations { get; set; }
        }
    }
    using FidaBlazorUI_Share.Models.Language;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    
    namespace FidaBlazorUI_Share.Models
    {
        public class Page
        {
            [Key]
            public int Id { get; set; }
            [Required]
            public string Name { get; set; }
            public string Url { get; set; }
            
            public List<LangTransPage> LangTransPages { get; set; }
    
        }
    }
    
    using FidaBlazor.Shared.Models.Account;
    using System.Collections.Generic;
    
    namespace FidaBlazor.Shared.Models.Menus
    {
        public class AppDynamicNavMenu : MenuBase
        {
            public bool Multi { get; set; }
            public User ApplicationUser { get; set; }
            public List<NavMenuItem> MenuItems { get; set; }
            public List<SubMenu> SubMenus { get; set; }
        }
    }
    
    using FidaBlazor.Shared.Enums;
    using FidaBlazor.Shared.Models.Account;
    using MailKit;
    using MimeKit;
    using MimeKit.Utils;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.IO;
    using System.Linq;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailMessage
        {
            public EmailMessage()
            {
                MessageId = MimeUtils.GenerateMessageId();
    
                ToAddresses = new List<EmailAddress>();
                FromAddresses = new List<EmailAddress>();
                CcAddresses = new List<EmailAddress>();
                BccAddresses = new List<EmailAddress>();
                Attachments = new List<EmailAttachment>();
                Headers = new List<EmailHeader>();
                References = new List<EmailMessageId>();
                ReplyTo = new List<EmailAddress>();
                MessageFlags = new List<EmailMessageFlag>();
            }
            public EmailMessage(MimeMessage message)
            {
                MessageId = message.MessageId;
                ToAddresses = new List<EmailAddress>();
                FromAddresses = new List<EmailAddress>();
                CcAddresses = new List<EmailAddress>();
                BccAddresses = new List<EmailAddress>();
                ReplyTo = new List<EmailAddress>();
                Attachments = new List<EmailAttachment>();
                Headers = new List<EmailHeader>();
                References = new List<EmailMessageId>();
                MessageFlags = new List<EmailMessageFlag>();
    
                ToAddresses.AddRange(message.To.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
                FromAddresses.AddRange(message.From.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
                CcAddresses.AddRange(message.Cc.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
                BccAddresses.AddRange(message.Bcc.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
                Body = !string.IsNullOrEmpty(message.HtmlBody) ? message.HtmlBody : message.TextBody;
                Subject = message.Subject;
                foreach (var attachment in message.Attachments)
                {
                    byte[] attachmentByteArray;
                    using var ms = new MemoryStream();
                    {
                        string fileName;
                        ContentType contentType = null;
                        if (attachment is MessagePart part1)
                        {
                            fileName = attachment.ContentDisposition?.FileName;
                            var rfc822 = part1;
    
                            if (string.IsNullOrEmpty(fileName))
                                fileName = "attached-message.eml";
                            rfc822.Message.WriteTo(ms);
                            attachmentByteArray = ms.ToArray();
                        }
                        else
                        {
                            var part = (MimePart)attachment;
                            fileName = part.FileName;
                            contentType = part.ContentType;
                            part.Content.DecodeTo(ms);
                            attachmentByteArray = ms.ToArray();
                        }
    
                        EmailAttachment mailAttachment = new EmailAttachment(fileName, attachmentByteArray, contentType);
                        Attachments.Add(mailAttachment);
                    }
                }
                foreach (var header in message.Headers)
                {
                    Headers.Add(new EmailHeader(header));
                }
                foreach (var header in Headers)
                {
                    if (header.Field.ToLower().Contains("Disposition-Notification-To"))
                    {
                        NeedReadReceipt = true;
                    }
                    if (header.Field.ToLower().Contains("Return-Receipt-To"))
                    {
                        NeedReadReceipt = true;
                    }
                }
                foreach (var intAdd in message.ReplyTo)
                {
                    ReplyTo.Add(new EmailAddress(intAdd.Name, intAdd.Name));
                }
                Date = message.Date;
                Importance = message.Importance;
                Priority = message.Priority;
                foreach (var messId in message.References)
                {
                    References.Add(new EmailMessageId(messId));
                }
                InReplyTo = message.InReplyTo;
                if (message.Sender != null)
                    Sender = new EmailAddress(message.Sender.Name, message.Sender.Address);
            }
    
            public List<EmailAddress> ToAddresses { get; set; }
            public List<EmailAddress> FromAddresses { get; set; }
            public List<EmailAddress> BccAddresses { get; set; }
            public List<EmailAddress> CcAddresses { get; set; }
            public List<EmailAttachment> Attachments { get; set; }
            public List<EmailHeader> Headers { get; set; }
            public List<EmailMessageId> References { get; set; }
            public List<EmailAddress> ReplyTo { get; set; }
            public List<EmailMessageFlag> MessageFlags { get; set; }
    
            [Key]
            public int Id { get; set; }
            public string MessageId { get; set; }
            public uint Uid { get; set; }
            public DateTimeOffset Date { get; set; }
            public MessageImportance Importance { get; set; }
            public MessagePriority Priority { get; set; }
            public string Subject { get; set; }
            public string Body { get; set; }
            public bool IsHtml { get; set; } = true;
            public bool NeedReadReceipt { get; set; }
            public bool NeedDeliveredReceipt { get; set; }
            public string InReplyTo { get; set; }
            public EmailAddress Sender { get; set; }
            public EmailMessageDirection  MessageDirection { get; set; }
            public User User { get; set; }
    
        }
    }
    
    using FidaBlazor.Shared.Models.Account;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailTemplate
        {
            [Key]
            public int Id { get; set; }
            public string ClassDataSource { get; set; }
            public string TemplateName { get; set; }
            public string Subject { get; set; }
            public string Body { get; set; }
            public bool NeedReadReceipt { get; set; }
            public bool NeedDeliveredReceipt { get; set; }
            public bool Shared { get; set; }
    
            public User User { get; set; }
    
            public List<EmailAttachment> Attachments { get; set; }
        }
    }
    
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account.Login
    {
        public class OldPassword
        {
            [Key]
            public int id { get; set; }
            public string oldPasswordHash { get; set; }
        }
    }
    
    using FidaBlazor.Shared.Enums;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class PhoneNumber
        {
            public PhoneNumber()
            {
    
            }
            public PhoneNumber(PhoneNumber newPhoneNumber)
            {
                CountryDialCode = newPhoneNumber.CountryDialCode;
                Number = newPhoneNumber.Number;
                NumberType = newPhoneNumber.NumberType;
                Notes = newPhoneNumber.Notes;
            }
            [Key]
            public int Id { get; set; }
            [Required]
            public string CountryDialCode { get; set; }
            [Required]
            public string Number { get; set; }
            public PhoneType NumberType { get; set; }
            public string Notes { get; set; }
    
            public User User { get; set; }
    
        }
    }
    
    using FidaBlazor.Shared.CustomValidators;
    using FidaBlazor.Shared.Enums;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class UserAddress
        {
            public UserAddress()
            {
    
            }
            public UserAddress(UserAddress newUserAddres)
            {
                NameId = newUserAddres.NameId;
                Street = newUserAddres.Street;
                Number = newUserAddres.Number;
                Flat = newUserAddres.Flat;
                Staircase = newUserAddres.Staircase;
                City = newUserAddres.City;
                PostalCode = newUserAddres.PostalCode;
                County = newUserAddres.County;
                Country = newUserAddres.Country;
                State = newUserAddres.State;
                AddressType = newUserAddres.AddressType;
            }
            [Key]
            public int Id { get; set; }
            [Required]
            public string NameId { get; set; }
            [Required]
            public string Street { get; set; }
            [Required]
            public string Number { get; set; }
            public string Flat { get; set; }
            public string Staircase { get; set; }
            [Required]
            public string City { get; set; }
            [Required]
            public string PostalCode { get; set; }
            [Required]
            public string County { get; set; }
            [Required]
            public CountryEnum Country { get; set; }
            public string State { get; set; }
    
            [AddressTypeNone(ErrorMessage = "Address Type None Not Allowed")]
            public AddressType AddressType { get; set; }
    
            public User User { get; set; }
        }
    }
    
    using FidaBlazor.Shared.Enums;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class UserIdentityNumber : INotifyPropertyChanged
        {
            public UserIdentityNumber()
            {
    
            }
            public UserIdentityNumber(UserIdentityNumber newIdentityNumber)
            {
                IdNumber = newIdentityNumber.IdNumber;
                IdType = newIdentityNumber.IdType;
                DocumentCopyUrl = newIdentityNumber.DocumentCopyUrl;
                DocumentThumbnail = newIdentityNumber.DocumentThumbnail;
                IssuingDate = newIdentityNumber.IssuingDate;
                ExpiringDate = newIdentityNumber.ExpiringDate;
                DocumentIssuer = newIdentityNumber.DocumentIssuer;
                IssuingPlace = newIdentityNumber.IssuingPlace;
            }
            [Key]
            public int Id { get; set; }
            [Required]
            public string IdNumber { get; set; }
            [Required]
            public IdNumberType IdType { get; set; }
    
            private string documentCopyUrl;
            public string DocumentCopyUrl
            {
                get => documentCopyUrl;
                set
                {
                    documentCopyUrl = value;
                    OnPropertyChanged("DocumentCopyUrl");
                }
            }
            public string DocumentThumbnail { get; set; }
    
            public DateTime IssuingDate { get; set; }
            public DateTime ExpiringDate { get; set; }
            public string DocumentIssuer { get; set; }
            public string IssuingPlace { get; set; }
    
            public User User { get; set; }
    
            public event PropertyChangedEventHandler PropertyChanged;
            protected void OnPropertyChanged(string propertyName)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    using FidaBlazor.Shared.Enums;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class UserMailAddress
        {
    
            private string _name;
    
            [Key]
            public int Id { get; set; }
            public string Name
            {
                get
                {
                    if (string.IsNullOrEmpty(_name))
                    {
                        return Address;
                    }
                    return _name;
                }
                set
                {
                    _name = value;
                }
            }
            [Required]
            [EmailAddress]
            [DataType(DataType.EmailAddress)]
            public string Address { get; set; }
            public EmailType MailType { get; set; }
    
            public User User { get; set; }
    
            public UserMailAddress(string address, EmailType mailType, string name = "")
            {
                _name = name;
                Address = address;
                MailType = mailType;
            }
            public UserMailAddress()
            {
    
            }
    
        }
    }
    
    using System;
    using System.ComponentModel.DataAnnotations;
    
    namespace FidaBlazor.Shared.Models.Account
    {
        public class UserProfile
        {
            [Key]
            public long Id { get; set; }
    
            public int UserId { get; set; }
            public User ApplicationUser { get; set; }
    
            public string LastPageVisited { get; set; } = "/";
            public bool IsNavOpen { get; set; } = true;
            public bool IsNavMinified { get; set; } = false;
            public int Count { get; set; } = 0;
            public DateTime LastUpdatedDate { get; set; } = DateTime.MinValue;
    
        }
    }
    
    namespace FidaBlazorUI_Share.Models.Language
    {
        public class LangTransPage
        {
            public int langTranslationId { get; set; }
            public int PageId { get; set; }
            public LangTranslation LangTranslation { get; set; }
            public Page Page { get; set; }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailAddress
        {
            private string _name;
    
            public EmailAddress(string name, string address)
            {
                _name = name;
                Address = address;
            }
    
            public int Id { get; set; }
            public string Name
            {
                get
                {
                    if (string.IsNullOrEmpty(_name))
                    {
                        return Address;
                    }
                    return _name;
                }
                set
                {
                    _name = value;
                }
            }
            public string Address { get; set; }
    
            public EmailMessage ToEmailMessage { get; set; }
            public EmailMessage FromEmailMessage { get; set; }
            public EmailMessage CcEmailMessage { get; set; }
            public EmailMessage BccEmailMessage { get; set; }
            public EmailMessage ReplyEmailMessage { get; set; }
            public EmailMessage SenderEmailMessage { get; set; }
    
        }
    }
    
    using MimeKit;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailHeader
        {
            public EmailHeader()
            {
    
            }
            public EmailHeader(Header header)
            {
                RawField = header.RawField;
                HeaderId = header.Id;
                Field = header.Field;
                Offset = header.Offset;
                RawValue = header.RawValue;
                Value = header.Value;
            }
    
            [Key]
            public int Id { get; set; }
            public byte[] RawField { get; }
            public HeaderId HeaderId { get; }
            public string Field { get; }
            public long? Offset { get; }
            public byte[] RawValue { get; }
            public string Value { get; set; }
    
            public EmailMessage EmailMessage { get; set; }
        }
    }
    
    using FidaBlazor.Shared.Enums;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailMessageFlag
        {
            [Key]
            public int Id { get; set; }
            public EmailMessageFlagEnum MessageFlag { get; set; }
    
            public EmailMessage EmailMessage { get; set; }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailMessageId
        {
            public EmailMessageId(string messageId)
            {
                MessageId = messageId;
            }
    
            [Key]
            public string Id { get; set; }
            public string MessageId { get; set; }
            public EmailMessage EmailMessage { get; set; }
        }
    }
    
    using MimeKit;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.IO;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace FidaBlazor.Shared.Email
    {
        public class EmailAttachment
        {
            private EmailAttachment()
            {
    
            }
            public EmailAttachment(string fileName, string fileNameUrl)
            {
                FileName = fileName;
                FileNameUrl = fileNameUrl;
                FileFullPath = fileNameUrl + "/" + fileName;
            }
            public EmailAttachment(string fileName, byte[] fileDataBytes)
            {
                FileName = fileName;
                FileDataBytes = fileDataBytes;
            }
            public EmailAttachment(string fileName, ContentType contentType)
            {
                FileName = fileName;
                ContentType = contentType;
            }
            public EmailAttachment(string fileName, byte[] fileDataBytes, ContentType contentType)
            {
                FileName = fileName;
                FileDataBytes = fileDataBytes;
                ContentType = contentType;
            }
    
            [Key]
            public int Id { get; set; }
            public string FileName { get; internal set; }
            public string FileNameUrl { get; internal set; }
            public string FileFullPath { get; internal set; }
            public string FileUrl { get; internal set; }
            public ContentType ContentType { get; }
            public byte[] FileDataBytes { get; internal set; }
    
            public EmailTemplate Template { get; set; }
            public EmailMessage EmailMessage { get; set; }
        }
    }
    
    namespace FidaBlazor.Shared.Models.Menus
    {
        public class NavMenuItem : MenuBase
        {
            public string Href { get; set; }
            public bool Disabled { get; set; }
            public bool AllowSection { get; set; }
            public string Content { get; set; }
            public string Icon { get; set; }
            public SubMenuHeader SubMenuHeader { get; set; }
        }
    }
    
    namespace FidaBlazor.Shared.Models.Menus
    {
        public class SubMenu : MenuBase
        {
            public bool Selected { get; set; }
            public bool Expanded { get; set; }
            public SubMenuHeader SubMenuHeader { get; set; }
            public SubMenuList SubMenuList { get; set; }
        }
    }
    
    namespace FidaBlazor.Shared.Models.Menus
    {
        public class SubMenuHeader : MenuBase
        {
            public string Content { get; set; }
            public NavMenuItem NavMenuItem { get; set; }
            public SubMenu SubMenu { get; set; }
        }
    }
    
    using System.Collections.Generic;
    
    namespace FidaBlazor.Shared.Models.Menus
    {
        public class SubMenuList : MenuBase
        {
            public SubMenu SubMenu { get; set; }
            public List<NavMenuItem> Items { get; set; }
            public List<SubMenu> SubMenus { get; set; }
        }
    }
    

    Ok I think that´s all

    Bye






















    Thursday, April 23, 2020 12:19 PM