0
votes

I am trying to connect to IBM DB2 database using EntityFrameworkCore 3.1 NuGet version. My DataAccess project is built using .NET standard 2.1 and I am adding reference of it in .NET Core 3.1 Web API project. I am registering DbContext in my Web API core project like below using built in MS dependency injection.

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddDbContext<RDSContext>(options => options
        .UseDb2(Configuration["connectionStrings_IBMDb"], p => p.SetServerInfo(IBMDBServerType.IDS)));
    ...
}

When I try to run, I am getting below error. Unable to understand the root cause.

System.TypeLoadException: 'Method 'Create' in type 'IBM.EntityFrameworkCore.Query.Internal.Db2SqlTranslatingExpressionVisitorFactory' from assembly 'IBM.EntityFrameworkCore, Version=3.1.0.400, Culture=neutral, PublicKeyToken=7c307b91aa13d208' does not have an implementation.'

My DataAccess project is having below references:

<PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.200" />
<PackageReference Include="IBM.EntityFrameworkCore" Version="3.1.0.200" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">

Any idea, how can I resolve this error?

1
You probably want to try updating the packages to the latest versions. Latest version of IBM.EntityFrameworkCore on NuGet is 5.0.0.20 - Glynn Hurrell
@GlynnHurrell: Package IBM.EntityFrameworkCore 5.0.0.200 is not compatible with netstandard2.1 (.NETStandard,Version=v2.1) - Sachin
In which case, you can try updating to 3.1.0.400. - Glynn Hurrell
@GlynnHurrell: Unfortunately updating it to .net core 3.1 is the last option as it is involving changing all other projects in solution. - Sachin
Sorry, I mean update the version IBM.EntityFrameworkCore to 3.1.0.400. It still supports NetStandard2.1 - Glynn Hurrell

1 Answers

0
votes

Check the version of your Microsoft EntityFrameworkCore package(s). I believe the latest version is 5.x. I ran into the same issue, but was able to resolve it by downgrading Microsoft.EntityFrameworkCore.SqlSever to 3.1.18. In addition to IBM EntityFrameworkCore (3.1.0.500), I was using EntityFrameworkCoreSqlServer component as well in my project (.net core 3.1 LTS).