I have added new property in my Entity Model as the new column has got added in DB table. But In that column might or might be there in other client database. So, How handle this? I have tried modelBuilder.Entity<Customer>().Ignore(customer => customer.FullName);
But it's not ignoring the property in entity. Because we have entity mapped class so it is not ignoring it.
Solution please?
Exclude or Ignore Property of an Entity model if column is not exist in database table
12.4k Views Asked by Sherlock At
2
There are 2 best solutions below
1

Just stop it. You're creating a world of pain for yourself.
If you want to have a dynamic schema, then you shouldn't be using Entity Framework at all.
Simplify and avoid all this headache by creating a migration that ensures that the field gets created in every single database (so that at runtime, the context will always match the database) and make sure the migration is executed before the app runs.
If you add the [NotMapped] attribute, entity framework will not create a column for it.
Or if you want to map the column, but in some databases it already exists, here's a migration which will add the column only if it does not exist.