title: How to implement IModelCacheKeyFactory in EF Core
body: <p>The story: in our multi-tenant app (one PostgreSql db, multiple schemas) we need to use one DbContext against multiple schemas.</p>
  
  <p>What I tried: holding a cache (Dictionary, where key is schema name, value is the context for that schema). When instatiating new context for another schema I can see that dbContext schema is still set to previous schema provided. I assume the model in context is cached internally by context type, so that is the reason I see this behavior?</p>
  
  <p>So above doesn't seem to work and I found that implementing IModelCacheKeyFactory should do the trick. Does anyone know what should go into <a href="https://docs.microsoft.com/en-us/ef/core/api/microsoft.entityframeworkcore.infrastructure.imodelcachekeyfactory" rel="noreferrer">Create</a> method though? There are no samples nor documentation anywhere. </p>
  
  <p>What I found:
  <a href="https://stackoverflow.com/questions/39499470/dynamically-changing-schema-in-entity-framework-core">Dynamically changing schema in Entity Framework Core</a> but it answers for EF6, so not much help.</p>