Missing IModel in Microsoft.EntityFrameworkCore.Internal

Viewed 84

With Microsoft.EntityFrameworkCore, Version=3.1.8.0, I can use Model as: context.Model.FindEntityType. But with version 6.0.0, I cannot use it anymore.

When I check assembly, it's difference as below, I can't see IModel in version 6:

  1. Version 3.1.8:
Assembly Microsoft.EntityFrameworkCore, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Internal;

namespace Microsoft.EntityFrameworkCore.Internal
{
    public interface IDbContextDependencies
    {
        IModel Model { get; }
        IDbSetSource SetSource { get; }
        IEntityFinderFactory EntityFinderFactory { get; }
        IAsyncQueryProvider QueryProvider { get; }
        IStateManager StateManager { get; }
  1. Version 6.0.0:
Assembly Microsoft.EntityFrameworkCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Internal
{
    public interface IDbContextDependencies
    {
        IDbSetSource SetSource
        {
            get;
        }
        IEntityFinderFactory EntityFinderFactory
        {
            get;
        }
        IAsyncQueryProvider QueryProvider
        {
            get;
        }

Please advise.

1 Answers

The Github Project MassTransit had the same Problem.
(Microsoft.EntityFrameworkCore 6.0 Breaking Changes #2980)

Possible Solution: replace IDbContextDependencies with DbContext (depended on .Net Version).
See Commit a1ebc6e.

I have the same problem, but not tested the solution within my code context.

Update: In my case first there was an error injecting DbContext directly, but there was a ...AspContext that had the DbContext (IdentityDbContext) inherited which fixed it for me.

Related