If you're only retrieving an object so that you can read its data, you can reduce your costs by turning off Entity Framework tracking. Which is exactly what you want to do in ASP.NET MVC, as long as you're careful.
This more fully-fledged version of Microsoft's object relational/mapper is now at the initial beta testing stage, with quicker startups and a number of fixes from the preview, but there's also more work to do to resolve some issues that can impact EF providers. Also: a list of new features of the EF Core 2.0 preview released at Build.
- By Michael Domingo
- 05/25/2017
The Entity Framework DbEntityEntry object lets you do all sorts of things you probably didn't think were possible, including getting the latest data from the database (without losing your current data) and invoking the .NET Framework validation subsystem.
If you're not using the Entity Framework DbCollectionEntry object when working with an entity class's related objects, then your application is running too slow. Using DbCollectionEntry lets you asynchronously retrieve related objects and get only the objects you want.
Entity Framework Core doesn't have lazy loading (at least, not yet). But you can fake it by using explicit loading, though it doesn't work quite the way you might want. In fact, it's probably a good idea to use this in Entity Framework 6.
If you decide on using an Enum with enumerated values in your Entity Framework class, here are the tools you'll need to make it work. But an enumerated value shouldn't be your first choice.
You probably use ToList to convert your LINQ results into Lists. It's almost as easy to convert any collection into a Dictionary whose items you can retrieve by key.
You can turn on logging for your Entity Framework code with a single line. Configuring it to write to a file takes only a little bit more effort.
There's more (and some less) in Entity Framework Core compared to Entity Framework 6, at least in version 1.0. While you can move to Entity Framework Core now, it might be too early for you.
Every once in a while you'll need to use the LINQ Join to get the data you want.
If you're using Skip and Take in LINQ to page through your data, a tweak to your syntax can cut your response time by as much as 10 percent as you page through your data.
Sometimes you want child objects retrieved with the parent object, and sometimes you don't. What you NEVER want is to retrieve child objects accidentally. Here's Peter's advice on how to get the best performance when loading child objects.
There are two attributes you can put on your entity class properties: one is a convenience, the other is essential, and both are required when the primary key for a table consists of two columns.
The first preview of the next incremental update to ASP.NET Core comes with a slew of new middleware components for speeding up app performance, while updates to .NET Core and Entity Framework Core come with mainly support additions.
- By Michael Domingo
- 10/26/2016
Among the list of bug fixes is one that squashes a potential security issue with ASP.NET Core View Component that can result in an elevation of privilege on systems.
- By Michael Domingo
- 09/14/2016
One way to slow down your application is to make multiple trips to the database. Here's a way to cut those trips in half (at least) and it has to do with the EntityFramework.Extended library.
By adding one open source library to your application (and adding two methods to your LINQ statements) you can cut the time spent on database updates and deletes in half.
Here's a tip about how to exploit Entity Framework's change tracking mechanism to -- possibly -- eliminate a trip to the database when you update an item. But, without some additional code, you probably can't use it.
Finalized versions of Microsoft's venerable software technologies are now generally available, and for Visual Studio 2015 U3, it includes the resolution of some high memory consumption issues that bedeviled some larger VS customers.
- By Michael Domingo
- 06/27/2016
In any real-world business, updating data isn't simple and changing the rows in the table is just the start of a complex set of processes. Fortunately, you can break those updates down into a bunch of simple processes that can be easily extended.