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:
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
In EF Core 3.0+ provider extension methods like Cosmos()
, SqlServer()
etc. as well as Relational()
have been removed. Now they are provided as direct extension methods of the corresponding metadata interfaces, with all previous properties replaced with Get
/ Set
extension methods.
In your case, the replacement of Cosmos().ContainerName
property are GetContainer and SetContainer extension methods:
metadata.SetContainer(dbSet.Name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With