Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4698

Expression not supported: Regex.IsMatch

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.21.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      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?

      Show
      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?

      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; }
          }
      } 

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: