【发布时间】:2017-09-09 09:08:27
【问题描述】:
我正在尝试连接到城堡活动记录中的多个数据库(使用 nhibernate。)我的配置文件如下所示:
<configSections>
<section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<activerecord>
<config type="Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.NavtrakOperationsDatabase`1, CommonSchemas">
<add key="hibernate.connection.connection_string" value="myconnstring" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
</config>
<config type="Navtrak.Business.Schemas.CommonSchemas.Models.Errors.ErrorsDatabase`1, CommonSchemas">
<add key="hibernate.connection.connection_string" value="Data Source=myconnstring" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
</config>
</activerecord>
然后我为每个数据库都有一个基本抽象类,如下所示:
public abstract class NavtrakOperationsDatabase<T> : ActiveRecordBase<T>
{
}
然后每个类都继承自这个。然后我像这样初始化活动记录:
ActiveRecordStarter.Initialize(typeof(SimpleModel).Assembly, ActiveRecordSectionHandler.Instance);
这给了我错误:
在配置中找不到方言
如果我把激活码改成这样:
ActiveRecordStarter.Initialize(
ActiveRecordSectionHandler.Instance,
typeof(NavtrakOperationsDatabase<>),
typeof(ErrorsDatabase<>)
);
然后我得到以下错误:
您访问了一个未正确初始化的 ActiveRecord 类。有两种可能的解释:对 ActiveRecordStarter.Initialize() 的调用不包括 Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.Application 类,或者 Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.Application 类没有用 [ActiveRecord] 属性修饰。
我显然不想在 Initialize 函数中包含每个类。
有什么想法吗?
【问题讨论】:
-
你用的是什么版本的activerecord?
-
@Mauricio Scheffer - 我正在使用 .NET 4 的最新 dll(我认为),大约一周前我下载了它们。
-
@Justin - 您能否更新以显示您使用的所有内容的最终语法?我正在尝试同样的事情,但无法克服您描述的错误。
标签: nhibernate activerecord castle-activerecord