While migrating a class library project from .netcore2.2 to .netcore 3.1, I am getting the following error:
Error CS1061 'IMutableEntityType' does not contain a definition for 'Cosmos' and no accessible extension method 'Cosmos' accepting a first argument of type 'IMutableEntityType' could be found (are you missing a using directive or an assembly reference?)
In the .netcore2.2 project I have used the following nuget packages:
- AutoMapper.Extensions.Microsoft.DependencyInjection
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.Cosmos
- Microsoft.Extensions.Configuration
Now as part of the migration process I have updated all the above nuget packages to their latest versions.
Her goes my DbContext class:
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options): base(options)
{
}
protected MyDbContext()
{
}
public DbSet<Address> Address { get; set;}
public DbSet<Languages> Languages { get; set;}
public DbSet<Contacts> Contacts { get; set;}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
OneCollectionPerDbSet(modelBuilder);
}
private void OneCollectionPerDbSet(ModelBuilder modelBuilder)
{
var dbSets = typeof(MyDbContext).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.PropertyType.IsGenericType && typeof(DbSet<>).IsAssignableFrom(p.PropertyType.GetGenericTypeDefinition()));
foreach (var dbSet in dbSets)
{
var metadata = modelBuilder.Entity(dbSet.PropertyType.GetGenericArguments()[0]).Metadata;
metadata.Cosmos().ContainerName = dbSet.Name;
}
}
}
In the above code, I am getting error in the method: OneCollectionPerDbSet as shown in the below line:
metadata.Cosmos().ContainerName = dbSet.Name;
Can anyone help me to fix this issue by providing their guidance