Recently one of my friends was migrating a project from ASP.Net MVC 5 to ASP.Net core 3.1. One of the challenges he faced is with the Index Attribute in data annotations. The .Net Core is not …
Recently one of my friends was migrating a project from ASP.Net MVC 5 to ASP.Net core 3.1. One of the challenges he faced is with the Index Attribute in data annotations. The .Net Core is not recognizing the Index attribute. When he copied his class from his MVC 5 project, he got the following error message.
Though the other data annotations accepted by .Net Core, this data attribute “Index” was throwing an exception.
“Index is not an attribute class”
Cool!. Let us dig into the details. You can find the related post on the Entity Framework Github page.
From the page, it is clear now, this is not a bug, the EF Core team didn’t migrate the Index Attribute from the EF 6. So we need to live with this.
Now the question arises, how we are going to add the Indexes to our Tables. The answer is to use the Fluent API in ASP.Net core.
You can refer to the following link on the Microsoft Site to get the details of how to apply the Index to a property.
So the solution is to replace the Index Attribute to the Fluent API, as below.
In real life, you will have many classes, and adding all classes using Fluent API inside OnModelCreating() method will make your code difficult to maintain. The solution is to create a separate class derived from IEntityTypeConfiguration. This will help us define all the related configurations in a single class and then apply the configurations from the OnModelCreating() method.
Let us apply the configuration class for the above. The following is the configuration class.
Once you have the configuration class, you can apply the configuration in the ModelCreating() method as follows.
In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.
We will learn about entity framework core in details i.e. what, how & why and see how to use it in ASP.NET Core Web API to implement CRUD operations. Though here we will be using entity framework in ASP.NET Core this can be implemented even in .NET Framework for your data persistence.
In this article, we will discuss the quickest way to use ASP.NET Core Identity for User Login and Registration in a new or existing MVC application.
Entity Framework Core EF Core 5.0 gets closer to a final release. RC2 is now available with bug fixes and a go-live license.
ＬＩＫＥ | ＣＯＭＭＥＮＴ | ＳＨＡＲＥ | ＳＵＢＳＣＲＩＢＥ What is ASP.NET Core?????? ASP.NET Core is an open source and cloud-optimized web framework for developing modern web appl...