1

I'm looking for a little "magic"

We have multiple applications written using entity framework. We need to update the scheme of a couple of columns - basically increasing the size of some account numbers columns. In our situation, we host the application for other customers and do not wish to increase the size of their account numbers but would like to have a single entity framework implementation for both.

The logic is the same with both tables - only the field length changes. This is a very large code base and refactoring, rewriting etc. the ideal solution.

Is there a way to specify in a config file what the field length is so it can be built at runtime?

Application Table Customer Name (256) Account NUmber (10)

Same Application Table Customer Name (256) Account Number (18)

glose
  • 507
  • 4
  • 12
  • Use [FluentApi](http://www.entityframeworktutorial.net/code-first/fluent-api-in-code-first.aspx) instead of [Data Annotations](http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx) – NaDeR Star Feb 11 '19 at 22:41

1 Answers1

1

You can write your own custom validation attribute with EF like in these examples: Custom validation attribute that compares the value of my property with another property's value in my model class

Pass variable data to ValidationAttribute

You can read your CustomerName property value, and based on the data you can validate your AccountNumber property. And in this custom validator you can read your config file.

hujtomi
  • 1,540
  • 2
  • 17
  • 23