0

EF Configuration

public class TB_R_LEAVE_REQ_APPROVAL_Configuration : DataUseLogConfiguration<Entities.TB_R_LEAVE_REQ_APPROVAL>
{
    public TB_R_LEAVE_REQ_APPROVAL_Configuration()
    {
        ToTable("TB_R_LEAVE_REQ_APPROVAL");

        HasKey(e => e.LEAVE_REQ_APPROVAL_ID);

        Property(e => e.LEAVE_REQ_APPROVAL_ID).HasColumnName("LEAVE_REQ_APPROVAL_ID").HasMaxLength(10);
        Property(e => e.LEAVE_REQ_ID).HasColumnName("LEAVE_REQ_ID").HasMaxLength(10);
        Property(e => e.HIERARCHY_LEVEL).HasColumnName("HIERARCHY_LEVEL");
        Property(e => e.HIERARCHY_RELATION).HasColumnName("HIERARCHY_RELATION").HasMaxLength(5);
        Property(e => e.POSITION_ID).HasColumnName("POSITION_ID").HasMaxLength(5);
        Property(e => e.EMP_ID).HasColumnName("EMP_ID").HasMaxLength(5);
        Property(e => e.APP_ROUND).HasColumnName("APP_ROUND");
    }
}

Entity

public class TB_R_LEAVE_REQ_APPROVAL : DataUseLog
{
    public string LEAVE_REQ_APPROVAL_ID { get; set; }
    public string LEAVE_REQ_ID { get; set; }
    public short HIERARCHY_LEVEL { get; set; }
    public string HIERARCHY_RELATION { get; set; }
    public string POSITION_ID { get; set; }
    public string EMP_ID { get; set; }
    public short APP_ROUND { get; set; }

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

when i do a query using table above, from produced SQL below EF uses columns that didn't exist in entity above:

insert into "TESSA"."TB_R_LEAVE_REQ_APPROVAL"("LEAVE_REQ_APPROVAL_ID", "LEAVE_REQ_ID", "HIERARCHY_LEVEL", "HIERARCHY_RELATION", "POSITION_ID", "EMP_ID", "APP_ROUND", "CREATED_DT", "CREATED_BY", "UPDATED_DT", "UPDATED_BY", "POSITION_NAME", "EMP_NAME", "CREATED_DT2", "APP_ROUND2", "IS_NEXT", "Discriminator")

and get error

ORA-00904: "Discriminator": invalid identifier

after more digging, i found out where these column are from viewmodel (that not set as entity in EF config) (this only used for view model)

public class LEAVE_REQ_APPROVAL : TB_R_LEAVE_REQ_APPROVAL
{
    public string POSITION_NAME { get; set; }
    public string EMP_NAME { get; set; }
    public DateTime? CREATED_DT2 { get; set; }
    public short? APP_ROUND2 { get; set; }
    public bool IS_NEXT { get; set; }
}

So how to tell EF to not use these ("POSITION_NAME", "EMP_NAME", "CREATED_DT2", "APP_ROUND2", "IS_NEXT", "Discriminator") as column??

I already tried manually migrate by deleting column, delete table and recreate it, but seems EF refuse to forget these columns

UPDATE 1: I add [NotMapped] on the LEAVE_REQ_APPROVAL, it kinda work, EF no longer use ("POSITION_NAME", "EMP_NAME", "CREATED_DT2", "APP_ROUND2", "IS_NEXT") column, but the Discriminator problem still exist

  • did u try NotMapped attribute ? https://stackoverflow.com/questions/10385248/ignoring-a-class-property-in-entity-framework-4-1-code-first – kudlatiger Feb 28 '18 at 04:34
  • well, not yet.... i try to not edit the entities, just the configs, is there any other way?? – Tanggon Jodi Ismana Feb 28 '18 at 04:41
  • It's been a while since I've been in EF, but isn't this a problem because you are using Table Inheritance? I seem to recall that a discriminator column is needed to help you map from the table to the correct model? Therefore the other columns are from some other entity that also maps to the same table? – Brendan Green Feb 28 '18 at 05:04

0 Answers0