From 569e39b58d12f21fb9c81eede08f2d71074d1711 Mon Sep 17 00:00:00 2001 From: alireza Date: Tue, 9 Jun 2026 02:13:29 +0330 Subject: [PATCH] Fix 'Invalid object name Provinces' error - reset migrations and switch to Migrate() --- Complex.Domain/Entities/City.cs | 2 + Complex.Domain/Entities/Province.cs | 2 + Complex.EndPoint/Program.cs | 35 +- .../20250601024740_add-complexPerson.cs | 144 ---- ... 20260608224155_InitialCreate.Designer.cs} | 28 +- .../20260608224155_InitialCreate.cs | 679 ++++++++++++++++++ .../ComplexDBContextModelSnapshot.cs | 24 +- 7 files changed, 740 insertions(+), 174 deletions(-) delete mode 100644 Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.cs rename Complex.Infrastructure/Migrations/{20250601024740_add-complexPerson.Designer.cs => 20260608224155_InitialCreate.Designer.cs} (96%) create mode 100644 Complex.Infrastructure/Migrations/20260608224155_InitialCreate.cs diff --git a/Complex.Domain/Entities/City.cs b/Complex.Domain/Entities/City.cs index 4f271c9..c3d13a4 100644 --- a/Complex.Domain/Entities/City.cs +++ b/Complex.Domain/Entities/City.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace Complex.Domain.Entities { + [Table("Cities")] public partial class City { public City() diff --git a/Complex.Domain/Entities/Province.cs b/Complex.Domain/Entities/Province.cs index 8bed573..0d83347 100644 --- a/Complex.Domain/Entities/Province.cs +++ b/Complex.Domain/Entities/Province.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace Complex.Domain.Entities { + [Table("Provinces")] public partial class Province { public Province() diff --git a/Complex.EndPoint/Program.cs b/Complex.EndPoint/Program.cs index cd0adbe..b83a6bc 100644 --- a/Complex.EndPoint/Program.cs +++ b/Complex.EndPoint/Program.cs @@ -123,6 +123,7 @@ builder.Services.AddDbContext( ); */ + builder.Services.AddApiVersioning(Options => { Options.AssumeDefaultVersionWhenUnspecified = true; @@ -177,13 +178,39 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); -// Ensure database is created and apply pending migrations +// Apply pending migrations and create database if not exists using (var scope = app.Services.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService(); - // EnsureCreated creates all tables from the model if they don't exist, - // while Migrate applies any pending migrations on top. - dbContext.Database.EnsureCreated(); + + // If the database was previously created with EnsureCreated() (no __EFMigrationsHistory), + // seed the history table so Migrate() knows the initial state + if (!dbContext.Database.GetAppliedMigrations().Any()) + { + try + { + // Check if any tables exist (meaning EnsureCreated was used before) + var tableCount = dbContext.Database.ExecuteSqlRaw( + "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"); + if (tableCount > 0) + { + // Create __EFMigrationsHistory if it doesn't exist and seed it + dbContext.Database.ExecuteSqlRaw( + "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '__EFMigrationsHistory') " + + "BEGIN " + + "CREATE TABLE [__EFMigrationsHistory] ([MigrationId] nvarchar(150) NOT NULL, [ProductVersion] nvarchar(32) NOT NULL, PRIMARY KEY ([MigrationId])); " + + "END " + + "IF NOT EXISTS (SELECT * FROM __EFMigrationsHistory WHERE MigrationId = '20260608224155_InitialCreate') " + + "INSERT INTO __EFMigrationsHistory (MigrationId, ProductVersion) VALUES ('20260608224155_InitialCreate', '6.0.3')"); + } + } + catch + { + // Database doesn't exist yet, Migrate() will create it + } + } + + dbContext.Database.Migrate(); // Seed essential reference data and test data await DataSeeder.SeedAsync(dbContext); } diff --git a/Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.cs b/Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.cs deleted file mode 100644 index 7bd76de..0000000 --- a/Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Complex.Infrastructure.Migrations -{ - public partial class addcomplexPerson : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - - migrationBuilder.CreateTable( - name: "ComplexPersons", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComplexId = table.Column(type: "uniqueidentifier", nullable: false), - PersonMobileNumberId = table.Column(type: "nvarchar(450)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_ComplexPersons", x => x.Id); - table.ForeignKey( - name: "FK_ComplexPersons_Persons_PersonMobileNumberId", - column: x => x.PersonMobileNumberId, - principalTable: "Persons", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_ComplexPersons_PersonMobileNumberId", - table: "ComplexPersons", - column: "PersonMobileNumberId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ComplexPersons"); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "UnitStates", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 234, DateTimeKind.Local).AddTicks(8929), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(2122)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "Units", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 234, DateTimeKind.Local).AddTicks(3769), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(7020)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "UnitCosts", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 234, DateTimeKind.Local).AddTicks(6906), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(118)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "Transactions", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 234, DateTimeKind.Local).AddTicks(717), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(3798)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "Persons", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 233, DateTimeKind.Local).AddTicks(7990), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(1127)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "IncomeCostTitles", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 233, DateTimeKind.Local).AddTicks(5558), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(8706)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "CostCycles", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 233, DateTimeKind.Local).AddTicks(2909), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(6075)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "ComplexUnitEvents", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 233, DateTimeKind.Local).AddTicks(1398), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(4581)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "ComplexManagers", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 232, DateTimeKind.Local).AddTicks(9811), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(2979)); - - migrationBuilder.AlterColumn( - name: "InsertTime", - table: "ComplexEntities", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(2025, 6, 1, 6, 15, 25, 232, DateTimeKind.Local).AddTicks(6954), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldDefaultValue: new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(207)); - } - } -} diff --git a/Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.Designer.cs b/Complex.Infrastructure/Migrations/20260608224155_InitialCreate.Designer.cs similarity index 96% rename from Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.Designer.cs rename to Complex.Infrastructure/Migrations/20260608224155_InitialCreate.Designer.cs index 4018c6c..28fae75 100644 --- a/Complex.Infrastructure/Migrations/20250601024740_add-complexPerson.Designer.cs +++ b/Complex.Infrastructure/Migrations/20260608224155_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Complex.Infrastructure.Migrations { [DbContext(typeof(ComplexDBContext))] - [Migration("20250601024740_add-complexPerson")] - partial class addcomplexPerson + [Migration("20260608224155_InitialCreate")] + partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -92,7 +92,7 @@ namespace Complex.Infrastructure.Migrations b.HasIndex("ProvinceId"); - b.ToTable("City"); + b.ToTable("Cities"); }); modelBuilder.Entity("Complex.Domain.Entities.ComplexEntity", b => @@ -119,7 +119,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(207)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(350)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -178,7 +178,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(2979)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(2221)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -254,7 +254,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(4581)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(3082)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -306,7 +306,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(6075)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(4033)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -349,7 +349,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(8706)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(5727)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -397,7 +397,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(1127)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(7277)); b.Property("IsActive") .HasColumnType("bit"); @@ -458,7 +458,7 @@ namespace Complex.Infrastructure.Migrations b.HasKey("ProvinceId"); - b.ToTable("Province"); + b.ToTable("Provinces"); }); modelBuilder.Entity("Complex.Domain.Entities.SmsCode", b => @@ -517,7 +517,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(3798)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(9359)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -588,7 +588,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(7020)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(1589)); b.Property("IsActive") .HasColumnType("bit"); @@ -659,7 +659,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(118)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(3756)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -705,7 +705,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(2122)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(4973)); b.Property("IsRemoved") .ValueGeneratedOnAdd() diff --git a/Complex.Infrastructure/Migrations/20260608224155_InitialCreate.cs b/Complex.Infrastructure/Migrations/20260608224155_InitialCreate.cs new file mode 100644 index 0000000..5924fff --- /dev/null +++ b/Complex.Infrastructure/Migrations/20260608224155_InitialCreate.cs @@ -0,0 +1,679 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Complex.Infrastructure.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "BasicTables", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Discriminator = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BasicTables", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Chats", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + PersonMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false), + ChatTypeId = table.Column(type: "tinyint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Chats", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ComplexUnitEvents", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UnitId = table.Column(type: "uniqueidentifier", nullable: true), + ComplexId = table.Column(type: "int", nullable: true), + EventDate = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: true), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(3082)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexUnitEvents", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Persons", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + FirstName = table.Column(type: "nvarchar(max)", nullable: true), + LastName = table.Column(type: "nvarchar(max)", nullable: true), + Gender = table.Column(type: "tinyint", nullable: true), + Avatar = table.Column(type: "varbinary(max)", nullable: true), + IsActive = table.Column(type: "bit", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(7277)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Persons", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Posters", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + ImagePath = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Posters", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Provinces", + columns: table => new + { + ProvinceId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProvinceTitle = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Provinces", x => x.ProvinceId); + }); + + migrationBuilder.CreateTable( + name: "SmsCodes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), + Code = table.Column(type: "nvarchar(max)", nullable: false), + Used = table.Column(type: "bit", nullable: false), + RequestCount = table.Column(type: "int", nullable: false), + InsertDate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SmsCodes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UnitStates", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComplexId = table.Column(type: "uniqueidentifier", nullable: true), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Icon = table.Column(type: "nvarchar(max)", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(4973)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_UnitStates", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ComplexPersons", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + PersonMobileNumberId = table.Column(type: "nvarchar(450)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexPersons", x => x.Id); + table.ForeignKey( + name: "FK_ComplexPersons_Persons_PersonMobileNumberId", + column: x => x.PersonMobileNumberId, + principalTable: "Persons", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "UserTokens", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TokenHash = table.Column(type: "nvarchar(max)", nullable: false), + TokenExp = table.Column(type: "datetime2", nullable: false), + RefreshToken = table.Column(type: "nvarchar(max)", nullable: false), + RefreshTokenExp = table.Column(type: "datetime2", nullable: false), + MobileModel = table.Column(type: "nvarchar(max)", nullable: false), + PersonId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserTokens", x => x.Id); + table.ForeignKey( + name: "FK_UserTokens_Persons_PersonId", + column: x => x.PersonId, + principalTable: "Persons", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Cities", + columns: table => new + { + CityId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProvinceId = table.Column(type: "int", nullable: true), + CityTitle = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Cities", x => x.CityId); + table.ForeignKey( + name: "FK_Cities_Provinces_ProvinceId", + column: x => x.ProvinceId, + principalTable: "Provinces", + principalColumn: "ProvinceId"); + }); + + migrationBuilder.CreateTable( + name: "ComplexEntities", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: true), + StateId = table.Column(type: "int", nullable: true), + AreaMeter = table.Column(type: "int", nullable: true), + YardMeter = table.Column(type: "int", nullable: true), + ElevatorCount = table.Column(type: "int", nullable: true), + WarehouseCount = table.Column(type: "int", nullable: true), + YearMake = table.Column(type: "int", nullable: true), + ParentId = table.Column(type: "uniqueidentifier", nullable: true), + Description = table.Column(type: "nvarchar(max)", nullable: true), + CityId = table.Column(type: "int", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(350)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexEntities", x => x.Id); + table.ForeignKey( + name: "FK_ComplexEntities_Cities_CityId", + column: x => x.CityId, + principalTable: "Cities", + principalColumn: "CityId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ComplexEntities_ComplexEntities_ParentId", + column: x => x.ParentId, + principalTable: "ComplexEntities", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "ComplexManagers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + ManagerMobileNumberId = table.Column(type: "nvarchar(450)", nullable: true), + StartDate = table.Column(type: "nvarchar(max)", nullable: false), + EndDate = table.Column(type: "nvarchar(max)", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(2221)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexManagers", x => x.Id); + table.ForeignKey( + name: "FK_ComplexManagers_ComplexEntities_ComplexId", + column: x => x.ComplexId, + principalTable: "ComplexEntities", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ComplexManagers_Persons_ManagerMobileNumberId", + column: x => x.ManagerMobileNumberId, + principalTable: "Persons", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "IncomeCostTitles", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: true), + TransactionTypeId = table.Column(type: "int", nullable: false), + ComplexId = table.Column(type: "uniqueidentifier", nullable: true), + RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: true), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(5727)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_IncomeCostTitles", x => x.Id); + table.ForeignKey( + name: "FK_IncomeCostTitles_BasicTables_TransactionTypeId", + column: x => x.TransactionTypeId, + principalTable: "BasicTables", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_IncomeCostTitles_ComplexEntities_ComplexId", + column: x => x.ComplexId, + principalTable: "ComplexEntities", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Units", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + UnitName = table.Column(type: "nvarchar(max)", nullable: false), + OwnerId = table.Column(type: "nvarchar(450)", nullable: true), + TenantId = table.Column(type: "nvarchar(450)", nullable: true), + IsActive = table.Column(type: "bit", nullable: false), + AreaMeter = table.Column(type: "int", nullable: true), + EmergencyTels = table.Column(type: "nvarchar(max)", nullable: true), + ParkingAreaMeter = table.Column(type: "int", nullable: true), + YardMeter = table.Column(type: "int", nullable: true), + PublicState = table.Column(type: "nvarchar(max)", nullable: true), + StateId = table.Column(type: "int", nullable: true), + Floor = table.Column(type: "int", nullable: true), + ManagerDescription = table.Column(type: "nvarchar(max)", nullable: true), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(1589)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Units", x => x.Id); + table.ForeignKey( + name: "FK_Units_ComplexEntities_ComplexId", + column: x => x.ComplexId, + principalTable: "ComplexEntities", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Units_Persons_OwnerId", + column: x => x.OwnerId, + principalTable: "Persons", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Units_Persons_TenantId", + column: x => x.TenantId, + principalTable: "Persons", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Units_UnitStates_StateId", + column: x => x.StateId, + principalTable: "UnitStates", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "CostCycles", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + Title = table.Column(type: "nvarchar(max)", nullable: false), + StartDate = table.Column(type: "date", nullable: false), + EndDate = table.Column(type: "date", nullable: false), + Amount = table.Column(type: "bigint", nullable: false), + EncouragementDay = table.Column(type: "int", nullable: false), + EncouragementAmount = table.Column(type: "bigint", nullable: false), + IncomeCostTitleId = table.Column(type: "int", nullable: true), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(4033)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CostCycles", x => x.Id); + table.ForeignKey( + name: "FK_CostCycles_ComplexEntities_ComplexId", + column: x => x.ComplexId, + principalTable: "ComplexEntities", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CostCycles_IncomeCostTitles_IncomeCostTitleId", + column: x => x.IncomeCostTitleId, + principalTable: "IncomeCostTitles", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "CostCycleUnit", + columns: table => new + { + CostCyclesId = table.Column(type: "uniqueidentifier", nullable: false), + UnitsId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CostCycleUnit", x => new { x.CostCyclesId, x.UnitsId }); + table.ForeignKey( + name: "FK_CostCycleUnit_CostCycles_CostCyclesId", + column: x => x.CostCyclesId, + principalTable: "CostCycles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CostCycleUnit_Units_UnitsId", + column: x => x.UnitsId, + principalTable: "Units", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "UnitCosts", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CostCycleId = table.Column(type: "uniqueidentifier", nullable: false), + UnitId = table.Column(type: "uniqueidentifier", nullable: false), + TransactionId = table.Column(type: "int", nullable: true), + Date = table.Column(type: "date", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(3756)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_UnitCosts", x => x.Id); + table.ForeignKey( + name: "FK_UnitCosts_CostCycles_CostCycleId", + column: x => x.CostCycleId, + principalTable: "CostCycles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UnitCosts_Units_UnitId", + column: x => x.UnitId, + principalTable: "Units", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Transactions", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TransactionTitleId = table.Column(type: "int", nullable: true), + TransactionPersianDate = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + TransactionDate = table.Column(type: "datetime2", nullable: false), + Amount = table.Column(type: "bigint", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: true), + CostCycleId = table.Column(type: "uniqueidentifier", nullable: true), + UnitId = table.Column(type: "uniqueidentifier", nullable: true), + FicheId = table.Column(type: "nvarchar(max)", nullable: true), + ComplexId = table.Column(type: "uniqueidentifier", nullable: false), + UnitCostId = table.Column(type: "bigint", nullable: false), + PersonId = table.Column(type: "nvarchar(450)", nullable: false), + InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(9359)), + IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), + RemoveTime = table.Column(type: "datetime2", nullable: true), + UpdateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Transactions", x => x.Id); + table.ForeignKey( + name: "FK_Transactions_CostCycles_CostCycleId", + column: x => x.CostCycleId, + principalTable: "CostCycles", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Transactions_IncomeCostTitles_TransactionTitleId", + column: x => x.TransactionTitleId, + principalTable: "IncomeCostTitles", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Transactions_Persons_PersonId", + column: x => x.PersonId, + principalTable: "Persons", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transactions_UnitCosts_UnitCostId", + column: x => x.UnitCostId, + principalTable: "UnitCosts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transactions_Units_UnitId", + column: x => x.UnitId, + principalTable: "Units", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Cities_ProvinceId", + table: "Cities", + column: "ProvinceId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplexEntities_CityId", + table: "ComplexEntities", + column: "CityId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplexEntities_ParentId", + table: "ComplexEntities", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplexManagers_ComplexId", + table: "ComplexManagers", + column: "ComplexId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplexManagers_ManagerMobileNumberId", + table: "ComplexManagers", + column: "ManagerMobileNumberId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplexPersons_PersonMobileNumberId", + table: "ComplexPersons", + column: "PersonMobileNumberId"); + + migrationBuilder.CreateIndex( + name: "IX_CostCycles_ComplexId", + table: "CostCycles", + column: "ComplexId"); + + migrationBuilder.CreateIndex( + name: "IX_CostCycles_IncomeCostTitleId", + table: "CostCycles", + column: "IncomeCostTitleId"); + + migrationBuilder.CreateIndex( + name: "IX_CostCycleUnit_UnitsId", + table: "CostCycleUnit", + column: "UnitsId"); + + migrationBuilder.CreateIndex( + name: "IX_IncomeCostTitles_ComplexId", + table: "IncomeCostTitles", + column: "ComplexId"); + + migrationBuilder.CreateIndex( + name: "IX_IncomeCostTitles_TransactionTypeId", + table: "IncomeCostTitles", + column: "TransactionTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_CostCycleId", + table: "Transactions", + column: "CostCycleId"); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_PersonId", + table: "Transactions", + column: "PersonId"); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_TransactionTitleId", + table: "Transactions", + column: "TransactionTitleId"); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_UnitCostId", + table: "Transactions", + column: "UnitCostId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_UnitId", + table: "Transactions", + column: "UnitId"); + + migrationBuilder.CreateIndex( + name: "IX_UnitCosts_CostCycleId", + table: "UnitCosts", + column: "CostCycleId"); + + migrationBuilder.CreateIndex( + name: "IX_UnitCosts_UnitId", + table: "UnitCosts", + column: "UnitId"); + + migrationBuilder.CreateIndex( + name: "IX_Units_ComplexId", + table: "Units", + column: "ComplexId"); + + migrationBuilder.CreateIndex( + name: "IX_Units_OwnerId", + table: "Units", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_Units_StateId", + table: "Units", + column: "StateId"); + + migrationBuilder.CreateIndex( + name: "IX_Units_TenantId", + table: "Units", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_UserTokens_PersonId", + table: "UserTokens", + column: "PersonId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Chats"); + + migrationBuilder.DropTable( + name: "ComplexManagers"); + + migrationBuilder.DropTable( + name: "ComplexPersons"); + + migrationBuilder.DropTable( + name: "ComplexUnitEvents"); + + migrationBuilder.DropTable( + name: "CostCycleUnit"); + + migrationBuilder.DropTable( + name: "Posters"); + + migrationBuilder.DropTable( + name: "SmsCodes"); + + migrationBuilder.DropTable( + name: "Transactions"); + + migrationBuilder.DropTable( + name: "UserTokens"); + + migrationBuilder.DropTable( + name: "UnitCosts"); + + migrationBuilder.DropTable( + name: "CostCycles"); + + migrationBuilder.DropTable( + name: "Units"); + + migrationBuilder.DropTable( + name: "IncomeCostTitles"); + + migrationBuilder.DropTable( + name: "Persons"); + + migrationBuilder.DropTable( + name: "UnitStates"); + + migrationBuilder.DropTable( + name: "BasicTables"); + + migrationBuilder.DropTable( + name: "ComplexEntities"); + + migrationBuilder.DropTable( + name: "Cities"); + + migrationBuilder.DropTable( + name: "Provinces"); + } + } +} diff --git a/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs b/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs index 379f38d..bb6641e 100644 --- a/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs +++ b/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs @@ -90,7 +90,7 @@ namespace Complex.Infrastructure.Migrations b.HasIndex("ProvinceId"); - b.ToTable("City"); + b.ToTable("Cities"); }); modelBuilder.Entity("Complex.Domain.Entities.ComplexEntity", b => @@ -117,7 +117,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(207)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(350)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -176,7 +176,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(2979)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(2221)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -252,7 +252,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(4581)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(3082)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -304,7 +304,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(6075)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(4033)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -347,7 +347,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 42, DateTimeKind.Local).AddTicks(8706)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(5727)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -395,7 +395,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(1127)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(7277)); b.Property("IsActive") .HasColumnType("bit"); @@ -456,7 +456,7 @@ namespace Complex.Infrastructure.Migrations b.HasKey("ProvinceId"); - b.ToTable("Province"); + b.ToTable("Provinces"); }); modelBuilder.Entity("Complex.Domain.Entities.SmsCode", b => @@ -515,7 +515,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(3798)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 153, DateTimeKind.Local).AddTicks(9359)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -586,7 +586,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 43, DateTimeKind.Local).AddTicks(7020)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(1589)); b.Property("IsActive") .HasColumnType("bit"); @@ -657,7 +657,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(118)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(3756)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -703,7 +703,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2025, 6, 1, 6, 17, 40, 44, DateTimeKind.Local).AddTicks(2122)); + .HasDefaultValue(new DateTime(2026, 6, 9, 2, 11, 55, 154, DateTimeKind.Local).AddTicks(4973)); b.Property("IsRemoved") .ValueGeneratedOnAdd()