# Is there way to optimize the code that uses Entity framework in .net core 6.0?

I'm very new to Entity Framework Core, so I'm concerned about whether I've done this query in the most efficient way possible.

Is there way to improve the code that uses Entity framework in .net core 6.0?

        var track = await this.DbContext.Tracks
.Include(t => t.Specialities)
.ThenInclude(s => s.Roles)
.ThenInclude(r => r.RoleEducation)
.ThenInclude(re => re.Education)
.Include(t => t.Specialities)
.ThenInclude(s => s.Roles)
.ThenInclude(r => r.RoleExperience)
.ThenInclude(re => re.Experience)
.Include(t => t.Specialities)
.ThenInclude(s => s.Roles)
.ThenInclude(r => r.SkillRoleRequirements)
.ThenInclude(s => s.MasteryLevel)
.ThenInclude(m => m.SkillType)
.Include(t => t.Specialities)
.ThenInclude(s => s.Roles)
.ThenInclude(r => r.SkillRoleRequirements)
.ThenInclude(s => s.Skill)
.ThenInclude(s => s.SkillType)
.FirstOrDefaultAsync(t => t.Id == id)
.ConfigureAwait(false);

• OnModelCreating there is AutoInclude option under Entity<TEntity>(x=> x.Navigation(...).AutoInclude()); in your case, it will take a couple of lines to include each navigation separately. but at the end it will get rid of all of these includes.
– iSR5
Aug 5 at 7:53
• @iSR5 - Thank you for your suggestion. 2 days ago