I'm developing an Entity Framework 6.1.2 library with .NET Framework 4.5.1 and C#.
I have this predicate:
Expression<Func<EXTERNAL_CODES, bool>> predicate = null;
List<string> codes = GetStartEntCodes(startingCode, quantity);
predicate = (e =>
e.USED == 0
&& codes.Contains(e.CODE)
&& e.CHINA_CODES_HEADER_ID == batch.Id
&& e.CODE_LEVEL == codeLevel
&& (e.BATCH_ID == batch.Id || e.BATCH_ID == null));
But this part && chinaCodes.Contains(e.CODE) doesn't work.
e.CODE is nvarchar(20) and each string on codes list contains only the first 15 characters.
I want to do this:
`WHERE CODE LIKE `codes.value%'; -- Note: `codes.value%' represents each value in codes list.`
How can I do this?
You can try something like that:
predicate = (e =>
e.USED == 0
&& codes.Any(x => x.StartsWith(e.CODE))
&& e.CHINA_CODES_HEADER_ID == batch.Id
&& e.CODE_LEVEL == codeLevel
&& (e.BATCH_ID == batch.Id || e.BATCH_ID == null));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With