© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
M B V R K

✅ EF Core Query Filter Exception

Hi,
I'm working with
EF Core
EF Core
with
PostgreSQL
PostgreSQL
, using
Code First
Code First
approach,
I have this Entity Type Configuration:
public class CategoryEntityConfig : IEntityTypeConfiguration<CategoryEntity>
{
    public void Configure(EntityTypeBuilder<CategoryEntity> builder)
    {
        builder.HasKey(c => c.Id);
        
        builder.Property(c => c.Name).IsRequired().HasMaxLength(50);
            
        builder.Property(c => c.Description).IsRequired(false);


        builder.Property(c => c.CreatedAt).IsRequired(true);
        builder.Property(c => c.CreatedBy).IsRequired(true);
        
        builder.Property(c => c.LastUpdatedAt).IsRequired(false);
        builder.Property(c => c.LastUpdatedBy).IsRequired(false);
        builder.Property(c => c.DeletedAt).IsRequired(false);
        builder.Property(c => c.DeletedBy).IsRequired(false);
        


        builder.HasOne(c => c.User)
            .WithMany(u => u.Categories)
            .HasForeignKey(c => c.UserId)
            .OnDelete(DeleteBehavior.Cascade);
            
        
        builder.HasQueryFilter( e => OnlyNonDeletedCategoriesQueryFilter(e));
    }
    
    
    /// <summary>
    /// Determines if a category entity is not deleted.
    /// </summary>
    /// <param name="categoryEntity">The category entity to check.</param>
    /// <returns><c>true</c> if the category entity is not deleted; otherwise, <c>false</c>.</returns>
    private static bool OnlyNonDeletedCategoriesQueryFilter(CategoryEntity categoryEntity)
    {
        return categoryEntity.IsDeleted == false;
    }
}
public class CategoryEntityConfig : IEntityTypeConfiguration<CategoryEntity>
{
    public void Configure(EntityTypeBuilder<CategoryEntity> builder)
    {
        builder.HasKey(c => c.Id);
        
        builder.Property(c => c.Name).IsRequired().HasMaxLength(50);
            
        builder.Property(c => c.Description).IsRequired(false);


        builder.Property(c => c.CreatedAt).IsRequired(true);
        builder.Property(c => c.CreatedBy).IsRequired(true);
        
        builder.Property(c => c.LastUpdatedAt).IsRequired(false);
        builder.Property(c => c.LastUpdatedBy).IsRequired(false);
        builder.Property(c => c.DeletedAt).IsRequired(false);
        builder.Property(c => c.DeletedBy).IsRequired(false);
        


        builder.HasOne(c => c.User)
            .WithMany(u => u.Categories)
            .HasForeignKey(c => c.UserId)
            .OnDelete(DeleteBehavior.Cascade);
            
        
        builder.HasQueryFilter( e => OnlyNonDeletedCategoriesQueryFilter(e));
    }
    
    
    /// <summary>
    /// Determines if a category entity is not deleted.
    /// </summary>
    /// <param name="categoryEntity">The category entity to check.</param>
    /// <returns><c>true</c> if the category entity is not deleted; otherwise, <c>false</c>.</returns>
    private static bool OnlyNonDeletedCategoriesQueryFilter(CategoryEntity categoryEntity)
    {
        return categoryEntity.IsDeleted == false;
    }
}


After running the app I get an exception that tells me that the
EF Core
EF Core
couldn't translate that query filter to
SQL
SQL
, as shown in the attached video.

Please any help to fix this issue guys ???
and massive thanks in advance <3
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

EF Core Global Query Filter Exception
C#CC# / help
4y ago
EF Core Global Query Filter with Nullable Exception
C#CC# / help
4y ago
✅ Ef-core query efficiency?
C#CC# / help
15mo ago
Logging EF-core exceptions
C#CC# / help
4y ago