Entity Framework Core 5.0

Date Published: October 14, 2020

Entity Framework Core 5.0

Entity Framework Core 5 adds indispensable many-to-many functionality.

I was recently working on an application in the MVC framework in .NET, working with Entity Framework and interacting with an SQL database. I was trying to create a many-to-many relationship between Member entities and Book entities (members could read several books, and books could be read by several members).

Unfortunately, prior to .NET 5 (which is still technically in preview mode), Entity Framework didn't really support many-to-many without you having to jump through a whole bunch of hoops.

After many hours of frustration and headaches over this issue (which I'd thought would be a minor hurdle in the actual feature I was trying to add to the application), I decided to just upgrade the application to .NET 5 and EF Core 5.0. This was a wise decision, because it made things so much easier. Seriously. If you're not working with .NET 5 and you're having problems with many-to-many relationships in EF Core, just update; you'll save yourself a lot of trouble.

Moving to EF Core 5.0 is actually pretty simple. First you need to migrate to .NET 5. You'll have to install the Preview version of Microsoft Visual Studio in order to work with .NET 5 (as of October 2020, at least). You'll have to edit your project's .csproj file with the proper version numbers. You can find a more detailed set of instructions from Microsoft here.

Then, you should also update your EF Core CLI (command line interface) tools. You can find those instructions here.

If you're interested in the other changes included in this new version of EF Core, you can check out the Plan for Entity Framework Core 5.0 and What's New in EF Core 5.0 docs pages.

Thanks for reading! I hope you find this and other articles here at ilyanaDev helpful! Be sure to follow me on Twitter @ilyanaDev.

ilyanaDev

Copyright © 2021