EF 上的歧义。使用 EF Core 7 的函数

Ambiguity on EF.Functions Using EF Core 7

提问人:Raphael Toselli 提问时间:11/13/2023 最后编辑:Raphael Toselli 更新时间:11/18/2023 访问量:72

问:

我刚刚将我的项目更新到 .NET 7 和 EF Core 7,编译时出现以下错误:

调用在以下方法或属性之间不明确:Microsoft.EntityFrameworkCore.MySqlDbFunctionsExtensions.DateDiffDay 和 Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateDiffDay

有问题的行使用 EF。用于执行 SQL 日期时间比较的函数扩展

query = query.Where(x => EF.Functions.DateDiffDay(DateA, DateB) >= DateToTest);

关于如何解决这个问题的任何指示?

以下是文件中的 nuget 包列表:.csproj

<ItemGroup>
    <PackageReference Include="AutoMapper" Version="12.0.1" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.7" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.300" />
    <PackageReference Include="AWSSDK.SQS" Version="3.7.300" />
    <PackageReference Include="CoreFtp" Version="1.4.0" />
    <PackageReference Include="CsvHelper" Version="30.0.1" />
    <PackageReference Include="EPPlus" Version="7.0.1" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="EntityFrameworkCore.MemoryJoin" Version="0.8.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0-rc.2.23480.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.0.3" />
    <PackageReference Include="RestSharp" Version="110.2.1-alpha.0.16" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
    <PackageReference Include="LinqKit.Core" Version="1.2.4" />
    <PackageReference Include="Hangfire.AspNetCore" Version="1.8.6" />
    <PackageReference Include="itext7" Version="8.0.2" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="7.0.2-dev-00546" />
    <PackageReference Include="serilog.sinks.graylog" Version="3.1.0" />
    <PackageReference Include="SSH.NET" Version="2023.0.0" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="6.2.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="6.2.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />
</ItemGroup>
C# ef-core-7.0

评论

1赞 gunr2171 11/13/2023
是否同时安装了 MySQL 和 SQL Server EF 包?
0赞 Raphael Toselli 11/13/2023
只是 SQLServer 的,因此这个错误的奇怪之处
0赞 gunr2171 11/13/2023
你能用你的 csproj 文件中的 nuget 包列表来编辑你的帖子吗?
1赞 Jeremy Lakeman 11/13/2023
非常确定官方在命名空间 MySql.EntityFrameworkCore.Extensions 中。但是Pomelo.EntityFrameworkCore.MySql将其扩展放在Microsoft.EntityFrameworkCore中。哪些可能通过您的某个依赖项公开?MySqlDbFunctionsExtensions
1赞 Charlieface 11/13/2023
但是,为什么首先要安装Pomelo呢?

答:

0赞 Raphael Toselli 11/13/2023 #1

无论出于何种原因,pomelo lib(我的 nuget 包中引用,因此此错误的奇怪之处......

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0">
            <Aliases>PomeloMySql</Aliases>
        </PackageReference>