Ambiguity on EF.Functions Using EF Core 7

244 views Asked by At

I've just updated my project to .NET 7 and EF Core 7, I'm getting the following error when compiling:

The call is ambiguous between the following methods or properties: Microsoft.EntityFrameworkCore.MySqlDbFunctionsExtensions.DateDiffDay and Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateDiffDay

The offending lines uses the EF.Functions extensions to execute SQL datetime comparisons

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

Any pointers on how to solve this?

Here's the list of my nuget packages from the .csproj file:

<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>
1

There are 1 answers

2
Raphael Toselli On BEST ANSWER

For whatever reason, the pomelo lib (that wasn't referenced in my nuget packages, hence the weirdness of this error...) was getting in the way of ef core server functions, i've solved the problem with an aliased include

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