简体   繁体   English

将NHibernate繁重的应用程序从具有多个模式的单租户迁移到多租户

[英]Moving an NHibernate-heavy application from single-tenancy to multi-tenancy with multiple schemas

I currently have a single-tenant application that uses fluent-nhibernate mappings to map C# objects to tables in my MySQL database. 我目前有一个单租户应用程序,该应用程序使用流利的hibernate映射将C#对象映射到我的MySQL数据库中的表。

As part of an effort to bring multi-tenancy to my application, I am considering having a single schema for each tenant. 作为将多租户引入我的应用程序的一部分,我正在考虑为每个租户使用一个单一的架构。 That is, I will have n schemas with identical table structures, n somewhere in the hundreds. 也就是说,我将拥有n具有相同表结构的模式,其中n在数百个位置中。

How can I rig up NHibernate, along with my fluent mappings, so that I can arbitrarily access the correct schema, and without having to replicate my C# objects to map to each schema? 如何装配NHibernate以及流畅的映射,以便可以随意访问正确的模式,而不必复制C#对象以映射到每个模式?

Not tested, but you can set in the SessionFactory (technically in its configuration) the default schema name. 未经测试,但是您可以在SessionFactory (技术上在其配置中)设置默认架构名称。 The property is hibernate.default_schema . 该属性是hibernate.default_schema So you could have multiple SessionFactory , one for each schema. 因此,您可以有多个SessionFactory ,每个架构一个。 Clearly you mustn't set the scema name at the Entity level. 显然,您不必在实体级别设置Scema名称。

Something like: 就像是:

var config = new Configuration();
... other configuration ...
config.Properties["hibernate.default_schema"] = "Foo"; // your schema name
ISessionFactory sf = config.BuildSessionFactory();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM