© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
antimatter8189

❔ Is saving data from DB into private fields is a good idea?

Lets say i have this class:
  public class LessonAppService :ApplicationService,
    ILessonService //implement the IBookAppService
    {
      
        private List<Lesson> _UserLessons;
}
  public class LessonAppService :ApplicationService,
    ILessonService //implement the IBookAppService
    {
      
        private List<Lesson> _UserLessons;
}


And this method:
   public async Task<List<LessonDTO>> GetUserLessons()
           
        {
            var queryable = await _lessonRepository.WithDetailsAsync();
            var lessonsQuery= queryable.Where(x=>x.CreatorId == CurrentUser.Id).OrderBy(x=>x.LessonNumber).Take(20);
            var lessons = await lessonsQuery.ToListAsync();
            _UserLessons = lessons;
            return ObjectMapper.Map<List<Lesson>, List<LessonDTO>>(lessons);
            
        }
   public async Task<List<LessonDTO>> GetUserLessons()
           
        {
            var queryable = await _lessonRepository.WithDetailsAsync();
            var lessonsQuery= queryable.Where(x=>x.CreatorId == CurrentUser.Id).OrderBy(x=>x.LessonNumber).Take(20);
            var lessons = await lessonsQuery.ToListAsync();
            _UserLessons = lessons;
            return ObjectMapper.Map<List<Lesson>, List<LessonDTO>>(lessons);
            
        }


Would it be good to operate on that private field of entites instead of making additional DB calls?
Same for example :
        private Lesson _activeLesson;
        private Lesson _activeLesson;

Any ideas?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Saving api json data to db
C#CC# / help
3y ago
Is using a blazor component from a service a good idea?
C#CC# / help
2y ago
Need help saving data from checkedlistbox
C#CC# / help
4mo ago
❔ Saving User Data
C#CC# / help
3y ago