I am maintaining this application (A) that is writing to the table of another application (B). The problem is that A writes to many B's and that the models have changed in newer versions of B.
Example: A has the entity Dog with columns: Name, Age, Sex
In most cases of B, this entity matches the table.
But the newest version of B Dog has the columns: Name, Age, Sex, FavoritFood (which does not allow nulls)
I can not change the database scheme of B, neither from code nor the sql server. If I do so, B would just redesign it to its needs. I can alter the Dog entity of A but this would need a distinction between newer and older versions of B.
A uses Entity Framework 6.2 as ORM.
My idea so far was as follows: Check if column exists, if not ignore the field.
protected override void OnModelCreating(DbModelBuilder builder) {
base.OnModelCreating(builder);
if (!Database.CompatibleWithModel(true)) {
builder.Entity<Dog>().Ignore(_ => _.FavoritFood);
}
}
Not only can't I access the context from within the OnModelCreating I also I find this possibility lacking, since it is very generic and I would like to check specifically for the FavoritFood column.
How can I accomplish this?