Posts

Table Inheritance with EF Core

Image
Note: this is an update to an old post on my old blog . Introduction EF Core 7  finally delivered a long-sought desire: all of the three  table inheritance patterns  are now implemented. These are: Table Per Hierarchy  ( TPH ) /  Single Table Inheritance : all columns for the properties of base and all derived classes are stored on the same, single, table, one for each base class (implemented in EF Core 1); Table Per Type  ( TPT ) /  Class Table Inheritance : columns for the properties of each class (abstract or otherwise) are stored on an individual table, and linked to tables that contain the columns for the properties for each base class through foreign keys (EF Core 5); Table Per Concrete Type  ( TPC ) /  Concrete Type Inheritance : a table exists for each concrete class which contains columns for each property of that class (EF Core 7). All of these patterns were discussed at length on  Martin Fowler ’s book,  Patterns of Ente...

Optimizing EF Core

Note: this is an update to an old post on my old blog . Introduction We all know O/RMs aren't the fastest tools when it comes to loading data, and Entity Framework Core is surely no exception. After all, they need to do a lot of operations, such as translating LINQ queries to SQL, instantiating the right entities, hydrating them (setting their properties from the database-retrieved values), taking a snapshot for the change-tracking functionality, etc, etc. But there, however, are a few things that we can do to help speed things a bit! Here are a few tips for you to make the best usage of Entity Framework Core, organised intro three topics: Optimising reads Optimising writes Other Optimising Reads Use Compiled Queries One of the things that can take some time is the translation from LINQ to SQL. This needs to happen all the time we execute a query from LINQ, unless, of course, we use a compiled query. Compiled queries are not exactly new in EF, and you can read...

The Evolution of .NET Dependency Resolution

Note: this is an update of an old post that is no longer available from my old blog . Introduction Dependency Resolution (RS), Dependency Injection/Dependency Inversion (DI) and Inversion of Control (IoC) are hot topics for a long time. Basically all frameworks are aware of it, or offer some mechanisms to help implement it. It all started a long time ago, however, and things are slightly confusing at the moment – but will get better! In this post, I won’t go through all of the details of all dependency resolution libraries in existence, instead I will only focus on Microsoft libraries. Also, I will only talk about generic dependency resolution, leaving out more specialized usages, such as WCF , WF and SharePoint , which also use similar concepts. Origins It all started with the venerable IServiceProvider interface. It basically provided a single method, GetService , that gave answer to “get me an implementation for this type”. That was it, the single parameter was a Type , and the r...