CreateFunction Like

SUAT SUPHI 61 Reputation points
2023-01-14T18:03:38.4233333+00:00

Hi,

I need an example about CreateFunction for like

Could you give me an example ?

https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/user-defined-functions

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,166 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,026 Reputation points
    2023-01-15T18:18:36.6166667+00:00
    connection.CreateFunction(
        "like",
        (string a, string b)  => a == b);
    

  2. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2023-01-19T09:29:28.83+00:00

    @SUAT SUPHI, Welcome to Microsoft Q&A, if you want to make the function to replace string.

    You could try the following code.

       _connection.CreateFunction("likeit",(string x,string y)=> y, isDeterministic: true);
    
    

    Then, you could call it in the commandtext like the following:

        string sql = "select * from Posts where Title==likeit('i','h')";
    
    

    The result is equal to

    select * from Posts where Title='h'.

    Note: I suggest that you don't use the like keyword in the sql because it already has some definitions.

    Hope my solution could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments