Question Details

No question body available.

Tags

c# sql postgresql npgsql ef-core-6.0

Answers (1)

October 8, 2025 Score: 2 Rep: 28,443 Quality: Medium Completeness: 60%

It is because EF Core LINQ translator limitations or bad optimizations. I would suggest to rewrite the query using multiple from clauses to achieve the desired result. Here is an example of how you can do this:

var query = from entity in _context.MusicalEntities from defaultFile in entity.MusicalEntityFiles .Where(x => x.IsDefault == true) .Take(1) .DefaultIfEmpty() from lastLesson = entity.MusicalEntitiesToLessons .Select(x => x.Lesson) .OrderByDescending(x => x.Date) .Take(1) .DefaultIfEmpty() select new DomainMusicalEntity { Id = entity.Id, OwnerId = entity.OwnerId, CreationDate = entity.CreationDate, Description = entity.Description, Title = entity.Title, IsPublic = entity.IsPublic, IsCompleted = entity.IsCompleted, YoutubeLink = entity.YoutubeLink, Author = entity.Author, UniqueId = entity.UniqueId, OriginId = entity.OriginId, DefaultFile = defaultFile, LastLessonDate = lastLesson.Date, };