-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
With 6.0.4, configuring an IModelCacheKeyFactory causes the following to be immediately thrown:
Unhandled exception. System.InvalidOperationException: The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.
at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetCollation(IReadOnlyModel model)
at Microsoft.EntityFrameworkCore.Metadata.IRelationalModel.get_Collation()
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.CreateCreateOperations()
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.CreateAsync(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in /home/roji/projects/test/Program.cs:line 12
at Program.<Main>$(String[] args) in /home/roji/projects/test/Program.cs:line 12
at Program.<Main>(String[] args)
This does not happen in 5.0. If this is intentional for some reason, we may be missing a breaking change note?
/cc @AndriySvyryd
Repro
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.ReplaceService<IModelCacheKeyFactory, MyModelCacheKeyFactory>();
}
public class MyModelCacheKeyFactory : IModelCacheKeyFactory
{
public object Create(DbContext context)
=> context.GetType();
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
}Reactions are currently unavailable