Posts

Showing posts with the label entity framework

Custom Validation and Class Level validation using Data Annotation in MVC .Net core application

Image
 In Previous article i have demonstrated about " Validations using entity framework data annotation in .Net core MVC " where i have implemented ready made validation types in MVC application. In this article i will be demonstrating about custom validation and class level validation using Data Annotation in MVC .Net core application. The custom validation will be very useful when we need to solve real time scenario where the ready made validation will not work. I also going to show about the class level validation which is also a type of custom kind validation available in data annotation using entity framework. Lets start the implementation, I going to use the same application which i have used in previous article. First we need to add few columns in existing employee table for validation demonstration as below. DateOfBirth DateOfJoin DateOfExit  After adding above fields my model class will look like below using ModelsExample.Attributes; using System; using System.Co

Validations using entity framework data annotation in .Net core MVC

Image
 In previous article we have learnt about working with Drop down in .Net Core MVC . now in this article we will work with the validations using entity framework data annotation. To implement the validation we just need to write minimal code and you are done, you do not need to write extra code for handling validation of your form.  Lets start the implementation, I am going to use the same application for this implementation which i have used in previous article mentioned above. We will use below validation types in this article however there are more validation types available in entity framework data annotation (like Range validation,compare validation,Custom Validation and more)  . Required validation Regular Expression validation String Length validation Max Length validation  First we need to import " _ValidationScriptsPartial " partial class in our view where we need to implement the validation using below syntax. @Html.Partial("_ValidationScriptsPartial")

CRUD operation using entity framework in .net core MVC application

Image
In Previous article " Setup Code first approach in .net core MVC application using entity framework " we have discussed setting up the code first approach in .net core application. We have created our first model in the sample project and we will be using the same project in this article. In this article we will doing the CRUD operation using entity framework in .net core MVC application. Visual studio provides scaffolding template for these operation but we will not use the scaffolding template for the CRUD operation rather we use the manual custom code for understating of the subject better.       Lets start the implementation. Before we start the crud operation activity we need to do some useful changes to entity migration. In previous article we have used the update-database command to migrate changes to database, but in real time web application this approach would not work so for that we need to make changes such that the migration changes will commit to database with

Setup Code first approach in .net core MVC application using entity framework

Image
In Previous article " .Net core MVC project structure explained step by step part 2 " we have discussed about .Net core MVC project structure. In this article we will be setting up the code first approach in .net core application. To control  and manage the entities we can opt for code first approach to design our database structure. To setup the entity framework in .net core app we need to add following nuget package to our projects. Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.Relational Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Tools Microsoft.EntityFrameworkCore.Design       I will show you how and where you need to use the above packages to setup the complete structure. I will use the same solution which i have used in previous article to setup the code first approach. Lets start the implementation. Go to solution explorer and right click on solution then click on new project then create the class library project and name it as