© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
66 replies
AlisterKB

Efcore Dynamic Linq, AND and OR

Hi,
a textbook dynamic filter for optional properties in a dto would look like something like this
var query = context.MyEntity
            .AsQueryable();
if (dto.Tags != null && dto.Tags.Any())
    query = query.Where(x => x.Any(t => dto.(t.Name)));
    .
    .
    .
    .
var query = context.MyEntity
            .AsQueryable();
if (dto.Tags != null && dto.Tags.Any())
    query = query.Where(x => x.Any(t => dto.(t.Name)));
    .
    .
    .
    .

above would result in an SQL query like SELECT * FROM table WHERE condition1 AND ... Condition N.
I'd like to dynamically do SELECT * FROM table WHERE condition1 OR ... Condition N.
looking online, here and there, mostly people refer to using Expressions and delegates. which is fine if that's the most sane way about (I used delegates few times btw Func, Action...), Extensions? just read about them. tldr of my understanding? it allows me to compile and invoke code at runtime (cool*2). here <=(short url: og link has NO SSL!) after explaining some of the concepts/solutions, it kinda recommends using LinqKit(never touched it before).
Q1: are the discussed solutions optimal way around this?
Q2: is linqkit bread and butter? should I just used it instead of writing my own predicate builder with Or and other abilities? (best to think twice before adding a packages, especially if I'm gonna use it in one method at least for now) .your help is much appreciated! 🙏
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
Next page

Similar Threads

✅ LINQ / EFCore
C#CC# / help
3y ago
✅ EFCore LINQ methods
C#CC# / help
3y ago
✅ Replacing Linq.Dynamic
C#CC# / help
4y ago
❔ efcore and repositorys
C#CC# / help
3y ago