I am trying to write a query in entity framework core where I am able to LPad the entity. I build up a PredicateBuilder by going through a loop and compare a string to the entity I'm trying to compare against
For example:
Model (Distributors):
public int Id {get;set;}
public decimal DistNo {get;set;}
For each loop in class
var searchPredicate = PredicateBuilder.New<Distributor>();
foreach (var code in codes)
{
searchPredicate.Or(x => EF.Functions.Like(x.DistNo.ToString(), $"{code}%"));
}
I have tried this:
searchPredicate.Or(x => EF.Functions.Like(System.Data.Entity.DbFunctions.Left("0" + x.DistNo.ToString(), 10), $"{code}%"))
But had no luck
What I'd like to happen is, when comparing "code" to "x.DistNo" is for the "x.DistNo" to be 0 padded on the left until its reached 10 characters. E.g. if x.DistNo in the db was 202930005 I'd want the query to see it as 0202930005 instead.
The oracle query I'm trying to replicate is: select * from distributors where lpad(dist_no, 10, '0') like '2%'