流畅的NHibernate MySQL批处理

时间:2013-11-29 13:33:33

标签: c# mysql nhibernate

我需要在我的NHibernate会话中应用批量调整。我正在使用MySQL。

在发现之后,NHibernate本身不支持MySQL的批量调整我安装了这个软件包:

http://www.nuget.org/packages/NHibernate.MySQLBatcher

包含MySQL的批处理程序。

然后我正在寻找可以注射配料器的点,并发现了这个:

Why doesn't NHibernate support batching on MySql

根据接受的答案,我找不到类似DataBaseIntegration()方法的内容。

以前有没有人通过这个?

3 个答案:

答案 0 :(得分:3)

我使用过这个包,它对我有用。

在我使用的配置下面:

var cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.MySqlDataDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty(NHibernate.Cfg.Environment.UseSecondLevelCache, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, "300");
cfg.SetProperty(NHibernate.Cfg.Environment.BatchSize, "1000");
cfg.SetProperty(NHibernate.Cfg.Environment.BatchStrategy,  typeof(MySqlClientBatchingBatcherFactory).AssemblyQualifiedName);

答案 1 :(得分:2)

如果使用代码语法映射,那么我在MySql中进行批处理的设置就像这样(NH 3.3 +): -

var configure = new Configuration().Configure();
configure.DataBaseIntegration(x =>
    {
        x.Dialect<MySQL5Dialect>();
        x.ConnectionStringName = "db";
        x.BatchSize = 50;
        x.Batcher<MySqlClientBatchingBatcherFactory>();

    })
    .Cache(x => x.UseQueryCache = true)
    .CurrentSessionContext<WebSessionContext>();

答案 2 :(得分:1)

如果使用FluentNhibernate,我的映射代码可能会帮助您:

Dim fConfig As FluentConfiguration
...
fConfig.ExposeConfiguration(Function(x) x.DataBaseIntegration(Sub(y)
         y.Batcher(Of MySQLBatcher.MySqlClientBatchingBatcherFactory)()
         y.BatchSize = 100
     End Sub)
相关问题