"Knowledge has to be improved, challenged, and increased constantly, or it vanishes."

Index is not an attribute class – Error while migrating from ASP.Net MVC 5 to .Net Core

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.

clip_image001

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.

https://github.com/dotnet/efcore/issues/1698

https://github.com/dotnet/efcore/issues/4050

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.

https://docs.microsoft.com/en-us/ef/core/modeling/indexes

So the solution is to replace the Index Attribute to the Fluent API, as below.

clip_image002

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<TEntity>. 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.

clip_image003

Once you have the configuration class, you can apply the configuration in the ModelCreating() method as follows.

clip_image004

Happy Coding!Smile

55 Comments

  • Thanks for Sharing this useful information.

  • Nice Info. Really useful.

  • More about this issue

  • I read the good information. Thank you very much.

  • I'm going to see some good stuff. I will visit you often in the future. Please also visit our blog.<a href="https://to-chelin07.com/">토토사이트 </a>

  • nice to meet you.I have a lot of questions about this site. We will visit you often.

  • <a href="https://megaslotgame.com/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1-ambpoker/ambpoker-%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%82%e0%b8%a1%e0%b8%8a%e0%b8%b1%e0%b9%88%e0%b8%99/">ambpoker โปรโมชั่น</a> รวมโปร ambpoker แจกเครดิตฟรี ทุกวี่วัน รวมทั้ง ก็พิเศษสุดๆเอาไว้ต้อนรับสมาชิกทุกคน <a href="https://megaslotgame.com/">MEGASLOTGAME</a> ไม่ว่าจะเป็น โปรโมชั่น pg สมัครเป็นสมาชิกใหม่รับ เครดิตฟรี50 หรือเป็นโบนัส

  • [url=https://megaslotgame.com/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1-ambpoker/ambpoker-%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%82%e0%b8%a1%e0%b8%8a%e0%b8%b1%e0%b9%88%e0%b8%99/]ambpoker โปรโมชั่น[/url] ambpoker แจกเครดิตฟรี ทุกวี่วัน รวมทั้ง ก็พิเศษสุดๆเอาไว้ต้อนรับสมาชิกทุกคน[url=https://megaslotgame.com/megaslotgame/]MegaSlot[/url]ไม่ว่าจะเป็น โปรโมชั่น pg สมัครเป็นสมาชิกใหม่รับ เครดิตฟรี50 หรือเป็นโบนัส

  • [url=https://megaslotgame.com/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1/%e0 %b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1-ambpoker/ambpoker-%e0%b9%82%e0%b8% 9b%e0%b8%a3%e0%b9%82%e0%b8%a1%e0%b8%8a%e0%b8%b1%e0%b9%88%e0%b8%99/]ambpoker Promotion [/url] ambpoker gives away free credit every day, including very special to welcome all members [url=https://megaslotgame.com/megaslotgame/]MegaSlot[/url] whether it is a pro Motion pg Sign up as a new member get 50 free credits or as a bonus

  • <a href="https://megaslotgame.com/%e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1/ %e0%b8%9a%e0%b8%97%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1-ambpoker/ambpoker-%e0%b9%82%e0% b8%9b%e0%b8%a3%e0%b9%82%e0%b8%a1%e0%b8%8a%e0%b8%b1%e0%b9%88%e0%b8%99/">ambpoker Promotion</a> includes pro ambpoker, giving away free credit every day, including a very special welcome to all members <a href="https://megaslotgame.com/">MEGASLOTGAME</a> whether Will it be a pg promotion, sign up as a new member, get 50 free credits or as a bonus

  • It's very interesting. And it's fun. This is a timeless article. I also write articles related to , and I run a community related to <a href="https://www.iflytri.com/">메이저사이트</a>. For more information, please feel free to visit !!
    FCH

  • it’s an amazing post and I learned a few tips worthy of keeping :). Thanks for sharing those and keep up the amazing work!

  • Excellent starter guide for Beginners! Thanks for putting your effort in putting out this great post.

  • I've seen some very helpful stuff. I found a lot of information, but your article was the most attractive and excellent. I will visit you often.

  • Really grateful information this gonna helpful stuff

  • Yt1s is a Great website for converting Youtube to Mp3 conversion if you want to download youtube videos to your devices. follow below steps

    First Open website of Yt1s - https://yt1s.mobi/

    Copy Youtube Video and Paste it into search box

    Press the Download button and download start fast and easily

  • Must be appreciated this article. Really Guys!

  • This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.</a> I would like to recommend a good topic if you wrote it. I'll leave my blog address below, so come and check it out. <a href="https://totomeoktwiblog.com/" target="_blank">메이저놀이터</a>

  • I was very impressed by your post. I want to write an article on your topic, but please visit my blog later.<a href="https://totoblogs.com/" target="_blank">먹튀검증 </a>

  • It's really helpful for us thanks for sharing

  • I have been looking for articles on these topics for a long time. <a href="http://images.google.es/url?sa=t&url=https%3A%2F%2Foncasino.io">casinocommunity</a> I don't know how grateful you are for posting on this topic. Thank you for the numerous articles on this site, I will subscribe to those links in my bookmarks and visit them often. Have a nice day

  • I like this blog, it gives me a lot of information I need. Thanks a lot
    https://711casino.net

  • easy and simple. I like how the content creator make this blog. Keep it up
    https://main7.net/%ec%83%8c%ec%a6%88%ec%b9%b4%ec%a7%80%eb%85%b8/

  • Masterpiece of content

  • Hello! If you or your company needs a professional data annotator, then I recommend that you do not waste your time looking for experts in this industry, but pay attention to our company of the best professionals. With the help of our company, you can hire a remote worker or a data labeling team. Each of our employees has several years of experience in annotation, classification and segmentation!

  • The modern world allows you to develop your own product without having to spend money on creating your own development department. The model of outsourcing recruitment and work of developers is many times more economical, and the results are better and faster achievable. Contact it outsourcing agentur and get such a team today.

  • A person who always sees only with his eyes. I am trying to write a comment for the first time. The postings about <a href="https://bulldogmoneysang.com/" target="_blank">플레이포커</a> you provide are really great... We'll be happy to see you in the future.

  • Hello! I recommend you use this online tool if you want to quickly and accurately find the passive voice in your texts. Correcting a passive voice with our tool will help you to master the text check in a couple of minutes and save you a lot of time. Test our assistant right now!

  • Hello friends! I would like to tell you about a tool that will help you significantly improve the quality of your text work! This instrument specializes in active voice and passive voice. After a quick check, it will identify the errors, point them out, and you can fix them!

  • Hello friends! If you're still having trouble using the passive voice, then I have additional hints for you to help! I recommend that you follow the link to learn a lot of useful and interesting things. And also to start using a specialized tool that will point out errors!

  • Good day, everyone. In any business it is important to write quality texts or documents. In this day and age, it's important to keep an eye on that. I want to <a href="https://www.activevoicedetector.com/">recommended you read</a> a resource that will help each of you. This site allows you to correct any grammatical errors, find flaws in the text and receive recommendations for improving the text.

  • Need help making a decision? Visit YesOrNoButton.com and let us help you out! Simply click on the "Yes" or "No" button and we'll show you the percentage of visitors who have chosen the same. It's a quick and easy way to make decisions on a variety of topics, and it's completely free to use. Check us out now at YesOrNoButton.com!

  • I've been reading all the articles related to <a href="https://hodumoney.com/" target="_blank">플레이포커머니상</a> for the past hour, but I don't know why I saw this post now. It seems like very useful information.

  • Of course, your article is good enough, <a href="http://images.google.ca/url?q=https%3A%2F%2Fevo-casino24.com%2F">majorsite</a> but I thought it would be much better to see professional photos and videos together. There are articles and photos on these topics on my homepage, so please visit and share your opinions.

  • Why couldn't I have the same or similar opinions as you? T^T I hope you also visit my blog and give us a good opinion. majorsite

  • "I had the pleasure of working with Metappfactory.com on a metaverse game project and was blown away by their expertise in Unity and VR development. Their team is incredibly talented and dedicated to creating immersive and engaging virtual experiences. They were also great communicators throughout the development process and always willing to go the extra mile to ensure the project was a success. Highly recommend them as a top-notch game development company for any metaverse project."

    <a href="#">https://www.metappfactory.com/gaming-development-service/</a>

  • Looking at this article, I miss the time when I didn't wear a mask. baccaratcommunity Hopefully this corona will end soon. My blog is a blog that mainly posts pictures of daily life before Corona and landscapes at that time. If you want to remember that time again, please visit us.

  • It's interesting. Thanks for sharing. Thank you.<a href="https://popmovie888.com/" rel="bookmark" title=" หนังใหม่ชนโรง "> หนังใหม่ชนโรง </a>

  • I have been looking for articles on these topics for a long time. safetoto I don't know how grateful you are for posting on this topic. Thank you for the numerous articles on this site, I will subscribe to those links in my bookmarks and visit them often. Have a nice day

  • Thank you for providing an excellent introductory guide for beginners!

  • I am sure this piece of writing has touched all the internet users, its really really good article on building up new blog. <a href="https://mtnamsan.com/" target="_blank">토토사이트</a>

  • <a href="https://www.opris.exchange/Thanks for sharing">

  • Getting to know new information feels like I'm going on a special trip, but since I logged on hereI feel like I'm traveling to a really cool world that I don't know, thank you very much for letting me have this special experience.

  • Hello, i feel that i noticed you visited my website thus i got here to return the choose?.I am trying to to find issues to enhance my web site!I guess its adequate to use some of your ideas!!

  • Great Information!!

  • Thanks for the blog !!!

  • Thanks for the info

  • Good post. I was constantly checking this blog and I got good information. I was impressed! ;) <a href="https://mtoceans.com/">먹튀검증</a>

  • I thought I did a good job reading your article. I've been inspired by countless articles, and yours is one of the most impressive! I hope you will read my article and feel the same way I do. Please visit my site <a href="https://speedmns.com/" target="_blank">플레이포커머니상</a> and read my articles too!

  • I didn’t have any expectations concerning that title, but the more I was astonished. The author did a great job. I spent a few minutes reading and checking the facts. Everything is very clear and understandable. I like posts that fill in your knowledge gaps. This one is of the sort.

  • I have understand your stuff previous to and you are just too magnificent.

  • Quality articles is the main to attract the viewers to pay a quick visit the website, that’s what this web page is providing.

  • thanks for sharing this article.

  • nice write-up

  • thanks for this information which helpful in my future.

Add a Comment

As it will appear on the website

Not displayed

Your website