Search code examples
entity-framework-core

EF Core 8 - RelationalConnectionDependencies does not contain a definition for 'With'


I am upgrading a project from .NET Core 2.1 to .NET 8 and as part of that, I also need to upgrade Entity Framework Core to 8.0.

In one of the code lines, the 'With' method is used, but that method is not available for use in EF Core 8.0 and therefore, I am getting an error.

So, is there any replacement method that I can use?

enter image description here

I tried to find a replacement method from EF Core Docs, but not able to find one.

Using statements:

using System.Data.Common;

using System.Data.SqlClient;

using Microsoft.EntityFrameworkCore;

using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;

using Microsoft.EntityFrameworkCore.Storage;

The code where the error occurs:

    var contextOptions = new DbContextOptionsBuilder()
    .UseSqlServerForAzure(
        connectionStringBuilder.ConnectionString,
        b => b.CommandTimeout(CommandTimeout ?? DefaultMasterConnectionCommandTimeout))
    .Options;
return new AzureSqlMsiRelationalConnection(Dependencies.With(contextOptions));

Solution

  • You should use with expression

    new AzureSqlMsiRelationalConnection(Dependencies with { ContextOptions = contextOptions });