SQL table vs Entity Framework MVC

I know a bit of MVC, but first I want to create MVC with a DataBase. I want to know one thing. I saw the following table on the Internet:

CREATE TABLE dbo.Payroll ( ID int PRIMARY KEY, PositionID INT, Salary decimal(9,2), SalaryType nvarchar(10), CHECK (Salary > 10.00 and Salary < 150000.00) ); 

I want to know if the CHECK element will lead to data validation in my website.

thanks in advance

+4
source share
2 answers

No, it will not automatically add confirmations to your site. It will force the use of this restriction on the database and will fail if the user enters a value outside this range.

You must add client-side acknowledgment to prevent unhandled errors from the database.

+2
source

Validation will not be performed in the web application / site, but in the database. Like a UNIQUE or FOREIGN KEY constraint, it will throw an error / exception if that constraint is violated

See this script: http://sqlfiddle.com/#!3/ede45 - delete the comment in the last line and see how it violates the restrictions and gives an error, the user sees that it has not been processed. You need to process such a record before it gets to the database, and the restriction will be just a check or recheck

+1
source

All Articles