Let’s get this out of the way first: I know that SessionFactory is immutable – I’m trying to change the Configuration at runtime and regenerate ISessionFactory.
Specifically, I have a Customer mapped that will have some fields added to its dynamic-component node at runtime. I would like to do something like this
var newSessionFactory = previousConfiguration
.RemoveClassMapping(typeof(Customer))
.AddXmlString(newMappingForCustomer)
.BuildSessionFactory();
However, I don’t see any obvious way to remove a mapping, is there anything I can do short of regenerating the entire Configuration?
It’s not possible. You’ll have to regenerate the
Configuration.My initial suggestion would be that you choose a different strategy for your model.
However, if you are determined to go with this :-), you can:
Configuration(that does not includeCustomer)MemoryStreamCustomermapping, if neededSessionFactoryCustomerConfigurationCustomermapping and create your finalSessionFactory