将文件中的数据库配置与 Fluent NHibernate 映射混合

发布于 2024-11-08 15:10:55 字数 914 浏览 3 评论 0原文

我偶然发现了以下问题:我想从配置文件配置数据库,但映射流畅(喜欢它!)配置代码如下所示:

var cfg = new Configuration();
cfg.Configure();
var fluentCfg = Fluently.Configure(cfg)
                        .Mappings(
                            m => m
                               .FluentMapping
                               .AddFromAssembly(Assembly.GetExecutingAssembly));

但是配置文件有一个属性:

<property name="proxyfactory.factory_class">
  NHibernate.ByteCode.LinFu.ProxyFactoryFactory, 
  NHibernate.ByteCode.LinFu
</property>

在 cfg.Configure(); 之后一切看起来都很好,配置指向 LinFu 字节码提供程序,但在第三行之后,我看到配置更改为使用 Castle。我查看了 Fluent 的代码,我可能是错的,但看起来他们正在 PersistenceConfiguration 的构造函数中的 PersistenceConfiguration.cs(第 50 行)中覆盖此属性:

values[ProxyFactoryFactoryClassKey] =  DefaultProxyFactoryFactoryClassName;

Fluent 是否需要 Castle?或者可能是我做错了什么或者这只是一个错误?

谢谢。

I stumbled upon the following problem: I wanted to configure the DB from config file but the mappings fluently (love it!) The configuration code looks like this:

var cfg = new Configuration();
cfg.Configure();
var fluentCfg = Fluently.Configure(cfg)
                        .Mappings(
                            m => m
                               .FluentMapping
                               .AddFromAssembly(Assembly.GetExecutingAssembly));

However the config file has a property:

<property name="proxyfactory.factory_class">
  NHibernate.ByteCode.LinFu.ProxyFactoryFactory, 
  NHibernate.ByteCode.LinFu
</property>

and after the cfg.Configure(); all looks good the configuration points to the LinFu bytecode provider BUT after the third line I see the configuration changed to using Castle. I looked in the Fluent's code and I might be wrong but it looks like they are overriding this property in PersistenceConfiguration.cs(line 50) in the constructor of PersistenceConfiguration:

values[ProxyFactoryFactoryClassKey] =  DefaultProxyFactoryFactoryClassName;

Does Fluent require Castle? Or may be I am doing something wrong or maybe this is just a bug?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还在原地等你 2024-11-15 15:10:55

我不知道这是否是您正在寻找的,但它可能对您有所帮助。您可以在代码中公开配置并进行所需的任何更改。

var cfg = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionStringName")).ShowSql())
                .Mappings(m =>
                {
                    m.FluentMappings.AddFromAssemblyOf<MapMarker>();
                    m.FluentMappings.Conventions.AddFromAssemblyOf<ConventionMarker>();
                })
                .ExposeConfiguration(x => x.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"));

I don't know if this is what you're looking for, but it might help you out. You can expose the configuration and make any changes that you need to, in code.

var cfg = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionStringName")).ShowSql())
                .Mappings(m =>
                {
                    m.FluentMappings.AddFromAssemblyOf<MapMarker>();
                    m.FluentMappings.Conventions.AddFromAssemblyOf<ConventionMarker>();
                })
                .ExposeConfiguration(x => x.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"));
稀香 2024-11-15 15:10:55

有一个从 Configure 链接出来的 ProxyFactoryFactory 方法。

Fluently.Configure()
  .ProxyFactoryFactory(name);

如果您不在 1.2 上,我相信它在 Database 调用下(请参阅 RexM 的答案)。

There's a ProxyFactoryFactory method chained off Configure.

Fluently.Configure()
  .ProxyFactoryFactory(name);

If you're not on 1.2, I believe it's under the Database call (see RexM's answer).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文