开发者

Any default Entity Framework validation with ASP.NET MVC3?

开发者 https://www.devze.com 2023-04-10 09:29 出处:网络
This question states that if Entity Framework and code first is used, some default validation is performed.I am using Entity Framework database-first and would like to use MVC 3 unobtrusive javascript

This question states that if Entity Framework and code first is used, some default validation is performed. I am using Entity Framework database-first and would like to use MVC 3 unobtrusive javascript validation. Is there s开发者_C百科ome default validation that will be performed, such as client-side checking for numbers when the database column is INTEGER, or client-side checking of string length against VARCHAR column lengths?


There should be no client side check unless you add the jQuery.

There are some default checking: DateTime field is always required. I don't have a complete list though.

For code first, you have detailed data annotation already in place, which specifies each field in the database. This annotation will enable a lot of default validation.

However, if it is database first, all you get from the EF is a group of partial classes (corresponding to the tables) with no annotation. The data annotation is usually added in a separate metadata file. Without this extra annotation, no default validation is there. EF simply hands the task of annotation to the programmer.


check this out for exactly what you are looking for. You might have to install Nuget and get some Asp.Net MVC 3 scaffolding to help you with the templates for these default validation you want. Good luck!

Hanlet

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号