I have a DB that I need all data to be able to load into. Lets say Table name is Person
, and person has a column SSID
(Don't worry this isn't the real table).
I bulk copy the data into this table, and don't want any issues, so SSID
is a nvarchar (8000)
. Then with EF I want to load this data into memory and validate that it's string lengths and such are correct, and fix them before pushing them to a final table (this part is not trivial, a transform is needed).
So my EF model:
public class Person
{
[MinLength(9)]
[MxnLength(9)]
public string SSID { get; set;}
//... more code
}
So since we're using code first, the MaxLength attribute will be used to determine the varchar length in the table, which we don't want to happen. I just want to be able to do Validator.Validate(person)
and get each validation issue.
Whats the best way to go about this?
One thought is 2 models, one for the actual DB, and another for validation. Seems like data binding from one to another might be expensive/tedious.
Another thought is to re-implement MaxLength and other attributes we need to do the same thing, but EF probably wouldn't know what to do with it so it wouldn't attempt to make a schema change.
Another thought is maybe there is a setting in EF to ignore certain data annotations?
Thanks for any help.