【问题标题】:'DbFunctions' does not contain a definition for 'ILike'“DbFunctions”不包含“ILike”的定义
【发布时间】:2022-01-27 16:16:15
【问题描述】:

我正在做一个 asp.net core 6.0 项目

query = query.Where(d => EF.Functions.ILike(d.Id.ToString(), $"%{keyword}%"));

当我尝试使用ILike

我收到此错误'DbFunctions' does not contain a definition for 'ILike' and no accessible extension method 'ILike' accepting a first argument of type 'DbFunctions' could be found (are you missing a using directive or an assembly reference?)

我也添加了参考using Microsoft.EntityFrameworkCore;

<PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
 </PropertyGroup>

 <ItemGroup>
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
</ItemGroup>

为什么会出现这个错误?

【问题讨论】:

  • 对于SQL Server,就是Functions.Like

标签: asp.net-core entity-framework-core asp.net-core-6.0 ef-core-6.0


【解决方案1】:

ILIKE 关键字特定于 PostgreSQL,因此您需要使用 PostgreSQL 提供程序 (Npgsql.EntityFrameworkCore.PostgreSQL) 才能使用 EF.Functions.ILike 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多