I wondering what should work faster in Entity Framework Core. The one query with loading of nested items using .AsSplitQuery or a sequential execution of queries? E.g. I have the following db model class:
public sealed class UserDbModel
{
public ICollection<OwnedClothesDbModel> OwnedClothes { get; set; }
public ICollection<OwnedHairDbModel> OwnedHairs { get; set; }
public ICollection<OwnedMakeupDbModel> OwnedMakeups { get; set; }
//Other properties and collections
}
Option 1 is to load all the data I need in a query:
var user = await _dbContext.Users
.Include(u => u.OwnedClothes)
.Include(u => u.OwnedHairs)
.Include(u => u.OwnedMakeups)
.AsSplitQuery()
.FirstOrDefaultAsync(u => u.UserId == userId)
//Work with the user and owned items.
Option 2 is to load collections separately.
var user = await _dbContext.Users.FirstOrDefault(u => u.UserId == userId);
var ownedClothes = await _dbContext.OwnedClothes.Where(oc => oc.UserId == userId);
var ownedMakeups = await _dbContext.OwnedMakeups.Where(om => om.UserId == userId);
var ownedHairs = await _dbContext.OwnedHairs.Where(oh => oh.UserId == userId);
//Work with the user and owned items.
I always thought that the first option should work faster, but some tests shows that it is not. The database I use is Postgres if it is necessary.