I got this error when I try to add a new "parameter" object into database, I have:
- "parameter" abstract class
- "parameter_manual_input_pattern" class inherits "parameter" abstract class
- "parameter_store_pattern"class inherits "parameter" abstract class
- "Store" class
Note that the class inherit only properties which is related to pattern.
[Table("parameter")]
public abstract class parameter
{
[Key]
public string Parameter_Id { get; set; }
public string Pattern { get; set; }
public virtual string x { get; set; }
public virtual string y { get; set; }
[ForeignKey("Store")]
public virtual string Store_Id { get; set; }
public virtual Store Store { get; set; }
}
public class parameter_manuel_input_pattern
{
public override string x { get; set; }
}
public class parameter_store_pattern
{
public override string y { get; set; }
[ForeignKey("Store")]
public override string Store_Id { get; set; }
public override Store Store { get; set; }
}
//DbContext
public class MyContext : DbContext
{
public MyContext() : base()
{ }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<parameter>()
.Map<parameter_store_pattern>(m => m.Requires("Pattern").HasValue("store"))
.Map<parameter_manual_input_pattern>(m => m.Requires("Pattern").HasValue("manual"));
}
}