Table Splitting in EF Core: When to Use It (and Why It Hurts Sometimes)
Your Customer
entity has 47 properties. Most queries only need the basic information: name, email, and contact details. But every time you load a customer, EF Core pulls all 47 columns from the database, including the large ProfileData
JSON blob that’s rarely used.
This is where table splitting can help: split your large entity into multiple classes that map to the same table, loading only what you need when you need it.
But table splitting is a double-edged sword. Use it wrong, and you’ll make performance worse, not better.
Understanding Table Splitting
Table splitting maps multiple entity classes to the same database table:
// Single table with many columns
CREATE TABLE Customers (
Id int PRIMARY KEY,
Name nvarchar(100),
Email nvarchar(200),
Phone nvarchar(20),
-- Frequently accessed columns above
ProfileData nvarchar(max),
Preferences nvarchar(max),
MarketingMetadata nvarchar(max),
LastLoginDetails nvarchar(max),
-- Rarely accessed columns below
CreatedAt datetime2,
ModifiedAt datetime2
);
Instead of one large entity, you create multiple focused entities:
// Frequently accessed data
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
// Navigation to extended data
public CustomerExtended Extended { get; set; }
}
// Infrequently accessed data
public class CustomerExtended
{ …