How can I use trimstart so entity framework will understand what to do?
Here is my query:
string number="123";
Workers.Where(x => x.CompanyId == 8).Where(x => x.Number.TrimStart('0') == number);
How can I make this query work without the AsEnumerable (there are a lot of workers in company 8)?
Try using SqlFunctions.PatIndex
for this. I tested a query similar to the one below with the values "000123"
, "000One"
, "abcde"
and it correctly selected rows with the values "123"
, "One"
, and "abcde"
.
Workers.Where(x => x.CompanyId == 8 &&
x.Number.Substring(SqlFunctions.PatIndex("%[^0]%", x.Number).Value - 1) == number);
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