作为yesterday's discussion的结果,我决定将Castle ActiveRecord用于我的ORM任务。我已根据starting guide向该类添加了属性。在解决了一些明显的错误之后,我受到了欢迎:
无法找到CLASS_XXX或其根类型Castle.ActiveRecord.ActiveRecordBase的配置,这通常表示配置尚未正确设置
错误消息中的CLASS_XXX是我的c#类名之一。有趣的是每次运行代码时CLASS_XXX都不同。我打开了log4net,我的log.txt没有捕获任何内容。所以,我猜测在进程到达NHibernate之前发生了错误。
以下是我的CSharp代码
log4net.Config.XmlConfigurator.Configure();
InPlaceConfigurationSource source =
new InPlaceConfigurationSource();
Assembly asm = Assembly.Load("DomainModel.Entities");
ActiveRecordStarter.Initialize(asm,source);
ActiveRecordStarter.CreateSchema();
有任何建议可以找到这个问题的真正原因吗?
答案 0 :(得分:1)
您错过了InPlaceConfigurationSource
(sample)的配置,或者您需要使用different initialization method。
答案 1 :(得分:1)
这可能不正确:
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
你需要做这样的事情:
string connectionString =
System.Configuration.ConfigurationManager.
ConnectionStrings["Northwind"].ToString();
InPlaceConfigurationSource source =
InPlaceConfigurationSource.Build(
DatabaseType.MSSQLServer2005, connectionString
);
或类似的东西:
string connectionString =
System.Configuration.ConfigurationManager.
ConnectionStrings["Northwind"].ToString();
IDictionary<string, string> properties =
new System.Collections.Generic.Dictionary<string, string>();
properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("connection.provider",
"NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", connectionString);
properties.Add("proxyfactory.factory_class",
"NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), (IDictionary<string, string>)properties);