简体   繁体   English

忽略继承的属性EF6

[英]Ignore Inherited Property EF6

TB_R_LEAVE_Configuration TB_R_LEAVE_Configuration

public class TB_R_LEAVE_REQ_ID_Configuration : DataUseLogConfiguration<Entities.TB_R_LEAVE_REQ_ID>
{
    public TB_R_LEAVE_REQ_ID_Configuration()
    {
        ToTable("TB_R_LEAVE_REQ_ID");

        HasKey(e => e.LEAVE_REQ_ID);
        HasRequired<TB_R_LEAVE_REQ>(e => e.TB_R_LEAVE_REQ);            

        Property(e => e.LEAVE_REQ_ID).HasColumnName("LEAVE_REQ_ID").HasMaxLength(10);
        Property(e => e.LEAVE_ID).HasColumnName("LEAVE_ID").HasMaxLength(5);
    }
}

DataUseLogConfiguration (abstract base class) DataUseLogConfiguration(抽象基类)

public abstract class DataUseLogConfiguration<T> : EntityTypeConfiguration<T> where T : DataUseLog
{
    public DataUseLogConfiguration()
    {
        Property(e => e.CREATED_BY).HasColumnName("CREATED_BY").HasMaxLength(5).IsRequired();
        Property(e => e.CREATED_DT).HasColumnName("CREATED_DT").IsRequired();
        Property(e => e.UPDATED_BY).HasColumnName("UPDATED_BY").HasMaxLength(5).IsOptional();
        Property(e => e.UPDATED_DT).HasColumnName("UPDATED_DT").IsOptional();
    }
}

I want to ignore all DataUseLogConfiguration properties 我想忽略所有DataUseLogConfiguration属性

  1. I tried use Ignore on TB_R_LEAVE_Configuration: 我尝试在TB_R_LEAVE_Configuration上使用忽略:

    Ignore(e => e.UPDATED_BY);

and this happen: 发生这种情况:

"The property 'UPDATED_BY' is not a declared property on type 'TB_R_LEAVE_REQ_ID'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property." “属性'UPDATED_BY'不是类型'TB_R_LEAVE_REQ_ID'的声明属性。通过使用Ignore方法或NotMappedAttribute数据注释,确认该属性未明确从模型中排除。确保它是有效的原始属性。”

  1. Without Ignore this happen: 如果不忽略,就会发生这种情况:

"ORA-00904: \\"Extent2\\".\\"UPDATED_BY\\": invalid identifier" “ ORA-00904:\\” Extent2 \\“。\\” UPDATED_BY \\“:无效的标识符”

The Data Model also use inherited base class 数据模型还使用继承的基类

public class TB_R_LEAVE_REQ_ID : DataUseLog
{
    public string LEAVE_REQ_ID { get; set; }
    public string LEAVE_ID { get; set; }

    public virtual TB_M_LEAVE TB_M_LEAVE { get; set; }
    public virtual TB_R_LEAVE_REQ TB_R_LEAVE_REQ { get; set; }
}

How i properly ignore properties on base class just using fluent API on TB_R_LEAVE_Configuration (im try to avoid changing the data model) 我如何仅使用TB_R_LEAVE_Configuration上的fluent API来适当地忽略基类的属性(我尽量避免更改数据模型)

thanks for everyone who try to help me, btw this is how i solve it with just edit the TB_R_LEAVE_REQ_ID_Configuration 谢谢所有尝试帮助我的人,顺便说一句,这就是我只需编辑TB_R_LEAVE_REQ_ID_Configuration即可解决的方法

public class TB_R_LEAVE_REQ_ID_Configuration : EntityTypeConfiguration<Entities.TB_R_LEAVE_REQ_ID>
{
    public TB_R_LEAVE_REQ_ID_Configuration()
    {
        ToTable("TB_R_LEAVE_REQ_ID");

        HasKey(e => e.LEAVE_REQ_ID);
        HasRequired<TB_R_LEAVE_REQ>(e => e.TB_R_LEAVE_REQ);

        Ignore(e => e.UPDATED_BY);
        Ignore(e => e.UPDATED_DT);
        Ignore(e => e.CREATED_BY);
        Ignore(e => e.CREATED_DT);

        Property(e => e.LEAVE_REQ_ID).HasColumnName("LEAVE_REQ_ID").HasMaxLength(10);
        Property(e => e.LEAVE_ID).HasColumnName("LEAVE_ID").HasMaxLength(5);
    }
}

notice that i changed the inheritance to EntityTypeConfiguration then just add the ignores as usual 请注意,我将继承更改为EntityTypeConfiguration,然后像往常一样添加了忽略项

Hope this help everyone in the future 希望这对以后的所有人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM