question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translating contains to like query

See original GitHub issue

Hello, the code bellow translates to Column` = "abc"` is there a way to make it translate to Column like "%abc%"

public static class IQueryableExtensions
{
        public static BinaryExpression GetBinaryExpression(ParameterExpression parameter, string property, object comparissonValue)
        {
              MemberExpression member = Expression.Property(parameter, property);
              ConstantExpression constant = Expression.Constant(comparissonValue, comparissonValue.GetType());
        
              MethodInfo method = typeof(StringHelpers).GetMethod("Contains", new[] { typeof(string), typeof(string) });
              var containsExp = Expression.MakeBinary(ExpressionType.Equal, member, constant, false, method);
              return containsExp;
        }
}

public static class StringHelpers
{
        public static bool Contains(string text, string text2)
        {
            return text.Contains(text2, StringComparison.InvariantCultureIgnoreCase);
        }
}

Environment details

linq2db version: 3.1.6 Database Server: MySql 8.0.21 Database Provider: ? Operating system: Windows 10 .NET Framework: .Net Core 3.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Jan 21, 2021

I don’t know about special literature. Everything I have learned when improving this library.

1reaction
DefinitelyADevcommented, Dec 16, 2020

@sdanyliv @viceroypenguin Thank you both very much for your time, it worked!

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF.Functions.Like in a compiled query could not be ...
You seems to be hitting yet another EF Core limitation. The problem is not the EF.Functions.Like method, but the usage of the interpolated ......
Read more >
Why is Select().Contains() ok while Any() is not?
Hi all; I first tried the following code: var statesIndirectDelete = await States .Where(s => deletedCountries.Any(c => c.Id == s.
Read more >
Cannot translate Contains for simple string comparison ...
After upgrading to 3.0 method using Where with string.Contains(string) inside throws translation error. Steps to reproduce Context.Entity.
Read more >
Complex Query Operators - EF Core
Sometimes, a query in one form translates to the server but if written in a different form doesn't translate even if the result...
Read more >
Translate queries with the interactive SQL translator
Describes how to translate a Teradata SQL query into a GoogleSQL query by using the BigQuery interactive SQL translator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found