两者都映射到表中的列,但配置为具有不同的可空性

时间:2019-05-20 05:20:31

标签: c# entity-framework-core

我正在尝试将两个实体映射到具有相同列的同一张表。区别在于每个实体的HasQueryFilter条件和参与引用的列。实体描述字典和实体之间的关系。启动它时,会收到以下消息:“ ...都映射到”中的“”列,但配置为具有不同的可空性。”

    public class KeyValuesEntity : BaseEntity
    {
        [Column("keyalphanr")]
        [StringLength(255)]
        public string keyalphanumber { get; set; }

        [Column("keydesc")]
        [StringLength(255)]
        public string keydescription { get; set; }

        [Column("keyvalint")]
        public int? keyvalueint { get; set; }
    }

    [Table("keyval")]
    public class KeyValuesBaseEntity : BaseEntity
    {
        [Column("keyalphanr")]
        [StringLength(255)]
        public string keyalphanumber { get; set; }

        [Column("keydesc")]
        [StringLength(255)]
        public string keydescription { get; set; }

        [Column("keyvalint")]
        public int? keyvalueint { get; set; }

        protected KeyValuesBaseEntity()
        {

        }
    }

    public sealed class OptionsEntity : KeyValuesBaseEntity
    {

    }

    var lboptionsBuilder = modelBuilder.Entity<LBOptionsEntity>();

    lboptionsBuilder.HasOne(lboptions => lboptions.optionholderKeyValue)
                .WithOne()
                .HasForeignKey<LBOptionsEntity>(lboptions => lboptions.optionholder)
                .HasPrincipalKey<OptionsEntity>(keyval => keyval.keyalphanumber);

0 个答案:

没有答案