Learning Entity Framework – Core 2.0


Overview

It is an open-source lightweight multi-platform ORM.  It runs on Windows, Mac OS, Linux, and UWP.  It does not contain all the features of EF6.  The goal was to learn how to use and configure EF core and if there are any advantages to using it.
 
I was very pleasantly surprised that is not that hard to use.  The real surprise was learning about the new features in EF core and that they were not in EF6.2.  I also learned that I could leverage some additional features from EF 6.2.

New for Core
  • Make sure you use the Microsoft NuGet package
  • Configuration is a little more involved
  • You must have an exe to apply for migrations
  • Many-to-many relations are better
  • Now support one-to-one
  • Has a nice logging system based on Microsoft.Extension.Logger.Ilogger
  • General logger now
  • Filter and order are now performed on the server instead of the client
  • Easier turning off the change tracker
  • Easier Add and Update
  • Migration files can be saved to source control.
  • Like operator was added
  • Global query filter
  • Context Pooling
  • Table Splitting
  • Owned types
  • The designer is no longer a provider


Items in EF6 that I learned:
  • Can Map to a view
  • Batch insert and update
  • Turn change tracking off for read-only queries
  • There is a unique constraint
  • Stop using the .Entry for save changes
  • Migrations are easier to use now
  • Supporting multiple database providers at the same time will kill migrations
  • Use context.table.Add();
  • Use context.table.Update();
  • Logger provides useful information on performance
  • Bulk Inserts are supported with AddRange.  I was hoping for more
  • When using the ForEach on the IEnumerable will not release the DB connection until the for loop is done.  If you have extra code in the for loop, you will see performance issues.  Do a .ToList() first
  • .Find is fastest
  • You can filter
  • Db.Entity.Find(s=>s.Name = “me”)
  • In the EF world, when they talk about disconnected, they are talking about data context, not a disconnected db.


Conclusion

With the addition of the new features listed above and performance changes, I am leaning towards porting my existing DAL implementation from EF6 to EF Core.  Overall there are a lot of performance improvements made to EF core.   

Comments

Popular posts from this blog

Yes, Blazor Server can scale!

Blazor new and improved Search Box

Blazor Wizard Step Component