Migration: filter: "[TenantId] IS NOT NULL"
migrationBuilder.CreateIndex( name: "IX_AppDeviceCheckRecords_Id_TenantId", table: "AppDeviceCheckRecords", columns: new[] { "Id", "TenantId" }, unique: true, filter: "[TenantId] IS NOT NULL");
How is this filter automatically added?I couldn't find it in the ABP source code。
https://github.com/abpframework/abp/blob/84396c21ae3fa723be968d2ddb045b8e946b06fe/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L702 https://github.com/abpframework/abp/blob/84396c21ae3fa723be968d2ddb045b8e946b06fe/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityTypeBuilderExtensions.cs#L25 https://learn.microsoft.com/en-us/ef/core/querying/filters
Thank you. I have other question: Assuming an entity has an ID, Code, and Name that uses soft deletion functionality. I set the code as a unique index. After I soft delete the data with Code="A", the user cannot query the data with Code="A" and cannot add the data with Code="A" anymore. The user will have questions. How can I solve them? According to your above answer, ISoftDelete also automatically added a query filter, but it did not affect the index.
builder.Entity<DeviceEntity>(b => { b.HasIndex(x => new { x.Id, x.TenantId }).IsUnique(); b.HasIndex(x => new { x.Code, x.TenantId }).IsUnique(); });
migrationBuilder.CreateIndex( name: "IX_AppDevices_Code_TenantId", table: "AppDevices", columns: new[] { "Code", "TenantId" }, unique: true, filter: "[TenantId] IS NOT NULL");
I understand now. If a field is of a nullable value type and an index is set, a filter will be automatically added during migration