fix: 修复套餐新增草稿默认值与开关落库
This commit is contained in:
@@ -677,9 +677,21 @@ public sealed class TakeoutAppDbContext(
|
||||
builder.Property(x => x.Name).HasMaxLength(128).IsRequired();
|
||||
builder.Property(x => x.Description).HasMaxLength(512);
|
||||
builder.Property(x => x.FeaturePoliciesJson).HasColumnType("text");
|
||||
builder.Property(x => x.PublishStatus).HasConversion<int>().HasDefaultValue(TenantPackagePublishStatus.Published).HasComment("发布状态:0=草稿,1=已发布。");
|
||||
builder.Property(x => x.IsPublicVisible).HasDefaultValue(true).HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
builder.Property(x => x.IsAllowNewTenantPurchase).HasDefaultValue(true).HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
builder.Property(x => x.PublishStatus)
|
||||
.HasConversion<int>()
|
||||
.HasDefaultValue(TenantPackagePublishStatus.Draft)
|
||||
.HasComment("发布状态:0=草稿,1=已发布。");
|
||||
|
||||
// 1. 解决 EF Core 默认值哨兵问题:当我们希望插入 false/0 时,若数据库配置了 default 且 EF 认为该值是“未设置”,会导致 insert 省略列,最终落库为默认值。
|
||||
// 2. (空行后) 将哨兵值设置为数据库默认值:true 作为哨兵,false 才会被显式写入,从而保证“可见性/可售开关”在新增时可正确落库。
|
||||
builder.Property(x => x.IsPublicVisible)
|
||||
.HasDefaultValue(true)
|
||||
.HasSentinel(true)
|
||||
.HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
builder.Property(x => x.IsAllowNewTenantPurchase)
|
||||
.HasDefaultValue(true)
|
||||
.HasSentinel(true)
|
||||
.HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
builder.Property(x => x.SortOrder).HasDefaultValue(0).HasComment("展示排序,数值越小越靠前。");
|
||||
builder.HasIndex(x => new { x.IsActive, x.SortOrder });
|
||||
builder.HasIndex(x => new { x.PublishStatus, x.IsActive, x.IsPublicVisible, x.IsAllowNewTenantPurchase, x.SortOrder });
|
||||
|
||||
Reference in New Issue
Block a user