Bug #84505 Using Contains method in expression with a variable throws exception in EF Core
Submitted: 13 Jan 2017 20:43 Modified: 9 Feb 2017 21:17
Reporter: Gabriela Martinez Sanchez Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.10 OS:Any
Assigned to: Gabriela Martinez Sanchez CPU Architecture:Any

[13 Jan 2017 20:43] Gabriela Martinez Sanchez
Description:
Using contains that uses a variable within a query throws the following exception:

When called from 'VisitChildren', rewriting a node of type 'System.Linq.Expressions.Expression' must return a non-null value of the same type. Alternatively, override 'VisitChildren' and change it to not visit children of this type.

EF Core 1.1

How to repeat:
Create a simple context with at least an entity like the following example:

    using (var context = serviceProvider.GetRequiredService<ComputedColumnContext>())
            {
                context.Database.EnsureCreated();
                var e = new Employee { FirstName = "Jos", LastName = "Stuart" };
                context.Employees.Add(e);
                context.SaveChanges();
                var avalue = "jo";
                var result = context.Employees.Where(t => t.FirstName.Contains(avalue)).ToList();
                Assert.Equal(1, result.Count);
                context.Database.EnsureDeleted();
            }

Expected results:
The Assert should be true.

Suggested fix:
Implement the missing visitchildren method.
[13 Jan 2017 20:43] Gabriela Martinez Sanchez
Verified.
[9 Feb 2017 21:17] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 6.10.1 release, and here's the changelog entry:

EF Core: Using the Contains method in an expression with a variable
generated an exception.

Thank you for the bug report.