© 2026 Hedgehog Software, LLC

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

How to return a named predicates

Hi friends,
I want to build a
Method
Method
that returns a set of
Predicates
Predicates


Example:
    private Predicate<Core.Entities.StudentAbsence>[] GetPredicates( SearchStudentAbsencesQuery query )
    {
        var whereFullNameContainsValue = new Predicate<Core.Entities.StudentAbsence>( x => ( x.StudentEnrollment.Student.FirstName + x.StudentEnrollment.Student.FamilyName ).Contains( query.Value ) );
        var whereSchoolSubjectTitleContainsValue = new Predicate<Core.Entities.StudentAbsence>( x => x.SchoolSubject.FullTitle.Contains( query.Value ) );
// Other predicates

        var predicates = new[]
                         {
                             whereFullNameContainsValue ,
                             whereSchoolSubjectTitleContainsValue ,
                             // Others
                         };
        
        return predicates;
    }
    private Predicate<Core.Entities.StudentAbsence>[] GetPredicates( SearchStudentAbsencesQuery query )
    {
        var whereFullNameContainsValue = new Predicate<Core.Entities.StudentAbsence>( x => ( x.StudentEnrollment.Student.FirstName + x.StudentEnrollment.Student.FamilyName ).Contains( query.Value ) );
        var whereSchoolSubjectTitleContainsValue = new Predicate<Core.Entities.StudentAbsence>( x => x.SchoolSubject.FullTitle.Contains( query.Value ) );
// Other predicates

        var predicates = new[]
                         {
                             whereFullNameContainsValue ,
                             whereSchoolSubjectTitleContainsValue ,
                             // Others
                         };
        
        return predicates;
    }


The Issue:
How do I can return those predicates but everyone with a name like properties, let me explain more

depending on the example I provided the use of that result will be like this:
var predicates = GetPredicates(Query);

var result = await db.<StudentAbsence>().Where( predicates[0] || predicates[1] //... ).ToListAsync()
var predicates = GetPredicates(Query);

var result = await db.<StudentAbsence>().Where( predicates[0] || predicates[1] //... ).ToListAsync()

as you will notice that to get every predicate I should use its
index
index
, instead of that I want when I got the predicates use their names like this following
var predicates = GetPredicates(Query);

var result = await db.<StudentAbsence>().Where( predicates.whereFullNameContainsValue  || predicates.whereSchoolSubjectTitleContainsValue //... ).ToListAsync()
var predicates = GetPredicates(Query);

var result = await db.<StudentAbsence>().Where( predicates.whereFullNameContainsValue  || predicates.whereSchoolSubjectTitleContainsValue //... ).ToListAsync()


I hope the explanation of the issue is clear, please is this even possible, if yes how do I can achieve this ? and massive thanks.
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

✅ Predicates
C#CC# / help
2y ago
❔ Predicates
C#CC# / help
4y ago
Named tuple on delegate return type [Answered]
C#CC# / help
4y ago
✅ How to return variables from a function
C#CC# / help
3y ago