[CSHARP-4698] Expression not supported: Regex.IsMatch Created: 27/Jun/23  Updated: 28/Oct/23  Resolved: 30/Jun/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.21.0

Type: Bug Priority: Unknown
Reporter: Oleksandr Poliakov Assignee: Oleksandr Poliakov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-4693 oDATA $matchesPattern support with LINQ3 Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

There are particular use-cases when Regex.IsMatch method could not be translated and throws ExpressionNotSupportedException exception. Here is minimal code to reproduce the issue (pay your attention to string convert operator it's vital to reproduce):

 

public class IsMatchTests : Linq3IntegrationTest
{
    [Fact]
    public void Regex_IsMatch()
    {
        var collection = CreateCollection();
 
        var query = collection.AsQueryable()
            .Where(i => Regex.IsMatch((string)i.A, @"\dB.*", RegexOptions.ECMAScript));
 
        var results = query.ToList();
 
        results.Should().OnlyContain(i => Regex.IsMatch(i.A, @"\dB.*", RegexOptions.ECMAScript));
    }
 
    private IMongoCollection<Data> CreateCollection()
    {
        var collection = GetCollection<Data>("test");
        CreateCollection(
            collection,
            new Data { Id = 1, A = "ABC" },
            new Data { Id = 2, A = "1Br" });
        return collection;
    }
 
    private class Data
    {
        public int Id { get; set; }
        public string A { get; set; }
    }
} 



 Comments   
Comment by Githook User [ 30/Jun/23 ]

Author:

{'name': 'Oleksandr Poliakov', 'email': '31327136+sanych-sun@users.noreply.github.com', 'username': 'sanych-sun'}

Message: CSHARP-4698: Expression not supported: Regex.IsMatch (#1120)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a3921d0c42600d85837edf278f3a58ca0b400ff8

Generated at Wed Feb 07 21:49:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.