Hi @Anjali Agarwal
how to put this regex in LINQ query.
To put the regex in the LINQ query, you need to convert the persons
as Enumerable or List, using the AsEnumerable
, AsAsyncEnumerable
, ToList
, or ToListAsync
methods.
Refer to the following sample:
var name = "Steve Ramsey"; //one space
var query = (from s in _dbcontext.Persons.AsEnumerable()
where (Regex.Replace(s.Name, @"\s+", " ").Contains(name))
select s).ToList();
The result as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion