Reputation: 37406
Is there anyway to make LINQ entities validate automatically according to the properties of the datatypes defined in the database?
For example, if my property maps to a varchar(40)
not null in the database, automatically validate the property to be not null and 40 length?
Upvotes: 2
Views: 238
Reputation: 3919
There is no built-in validation system, but you can do what you want by inspecting the ColumnAttribute on the properties of your LINQ to SQL entities. Basically you search for the text "varchar" and, if found, parse the maximum length from the attribute (the "40" in "varchar(40)").
There are many different ways to do it. See here or here or you'll find other implementations by searching around.
Upvotes: 1