簡體   English   中英

EF Core HasDiscriminator和可空標識符

[英]EF Core HasDiscriminator with nullable discriminator

我試圖指定我在實體上已經有一個鑒別器,但不確定如何在此處表示。

它們之間的區別在於一列是否為空。 顯然,在它為null的情況下,我可以明確地將其放入,但是對於不為null的情況,我該怎么辦?

protected override void OnModelCreating(ModelBuilder modelBuilder) {
    modelBuilder.Entity<Schedule>()
        .HasDiscriminator<Guid?>("ManagerId")
        .HasValue<EmployeeSchedule>(null)
        .HasValue<ManagerSchedule>(/* What goes here? */);
}

通過將屬性bool IsManagerSchedule置於Schedule ,然后使用.HasValue<ManagerSchedule>(true).HasValue<EmployeeSchedule>(false);

嘗試刪除手動配置,然后:

public class EmployeeSchedule {
    // properties of all employees...
}

public class ManagerSchedule {
    public TYPE PropertyName {get; set;} // discriminator property
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM