In this post, we will see how to resolve Fetch rows from DB where multiple columns have to match supplied values in ef core
Question:Input data comes with a list of multiple (5) properties and I would like to fetch records from the DB where one row matches any row from the input list like so:
I tried lookging at the examples given in Query where multiple columns have to match a value set simultaneously in EF Core but I’m unsure how to produce expressions while matching 5 values.
Also, whenever I try to build expressions something like in this example, however it always produces a stackoverflow exception.
Option 1: N-separate queries:
- Pro: simple, works
- Cons: wasteful
Option 2: Build OR query at runtime
- Pro: fast
- Cons: requires LinqKit PredicateBuilder: https://www.albahari.com/nutshell/predicatebuilder.aspx
If you have better answer, please add a comment about this, thank you!