Know the Validation – Explore Inbuilt Validations

We have learned and built different kinds of relationships supported by EF in this chapter. We started with regular one-to-one, one-to-many, and many-to-many relationships, and from there applied a few Fluent API methods to achieve relationships. Then, we covered different usages of the Fluent API on the terminologies we saw in Chapter 3, Relationships – Terminology and Conventions. Finally, we have seen the behavior of Delete operations on dependent entities if a principal entity gets deleted. These sections dealt with relationships, but never looked at validations, except where required. Let's explore them in the next chapter.

We have explored about different kind in-built relationships, leveraged Fluent API methods in creating relationships. We have also looked at the use of the Fluent API on navigational properties, mandating certain fields using isRequired(), implementing principal and foreign keys using HasPrincipalKey() and HasForeignKey() methods, and much more. 

In this chapter, we will address the following concerns with respect to data security:

  • What should be done to the data before we send it over the network?
    • Add certain rules/conditions to the data (defined in the model)
    • Validate the models both on the client-side and server-side (supported out of the box)
  • How are the validations handled in ASP.NET?
    • We started with JavaScript-based validation, then control-driven validations were performed and finally from MVC we started using data model-driven validations
    • We will be exploring how MVC handles validation through the data model
  • Do we need to explicitly use HTML5 validation?
    • Not required, as rendering the MVC engine internally converts the data-model driven validations into HTML5 data-attribute driven validations

We will be covering all built-in validations in this chapter, listed as follows:

  • Built-in validations
  • Required field validation
  • EmailAddress field validation
  • Compare field validation
  • Url field validation
  • MinLength field validation
  • MaxLength field validation
  • RegularExpression field validation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset