Validating Data
As in LINQ to SQL, you can take advantage of partial methods to accomplish custom data validations; however, there is an important difference. Entity Data Model generation takes care of providing a better mapping between SQL Server types and .NET types. Chapter 25 provides an example of the custom validation rule for ensuring that a string is not greater than 20 characters. In the Entity Framework this is not necessary. For example, take a look at the Properties window showing properties for the Product.QuantityPerUnit property as previously shown in Figure 27.12.
Notice how there is a Max Length property that limits the size of the string to 20 characters. To understand what happens, try to run the AddProduct method previously ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access