2016-07-29 64 views
0

我想创建一个POC应用程序来探索Castle.ActiveRecord,但由于某种原因,我得到“无法编译映射文档:(字符串)”错误信息。这是一个非常基本的代码。我检查了Castle.ActiveRecord的现有文档,但我无法弄清楚这个问题的原因。当然,它看起来像某种配置故障。Castle.ActiveRecord - 无法编译映射文档:(字符串)

的Program.cs

class Program 
{ 
    static void Main(string[] args) 
    { 
     IConfigurationSource source = ConfigurationManager.GetSection("activerecord") as IConfigurationSource; 
     ActiveRecordStarter.Initialize(source, typeof(Student)); 

     var students = Student.FindAll(); 
     foreach (var student in students) 
     { 
      Console.WriteLine(student.Name); 
     } 
    } 
} 

Student.cs

[ActiveRecord("Student")] 
public class Student : ActiveRecordBase<Student> 
{ 
    [PrimaryKey] 
    public int Id { get; set; } 

    [Property] 
    public string Name { get; set; } 

    [Property] 
    public string Grade { get; set; } 
}  

的App.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/> 
    </configSections> 

    <activerecord isWeb="true"> 
    <config> 
     <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> 
     <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/> 
     <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> 
     <add key="hibernate.connection.connection_string" value="Server=localhost;Database=Art_DEV;Trusted_Connection=True;"/> 
    </config> 
    </activerecord> 

    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
</configuration> 

我得到的错误是:

{"Error adding information from class ConsoleApplication1.Student to NHibernate. Check the inner exception for more information"} 
    Data: {System.Collections.ListDictionaryInternal} 
    HResult: -2146233088 
    HelpLink: null 
    InnerException: {"Could not compile the mapping document: (string)"} 
    Message: "Error adding information from class ConsoleApplication1.Student to NHibernate. Check the inner exception for more information" 
    Source: "Castle.ActiveRecord" 
    StackTrace: " at Castle.ActiveRecord.ActiveRecordStarter.AddXmlString(Configuration config, String xml, ActiveRecordModel model)\r\n at Castle.ActiveRecord.ActiveRecordStarter.AddXmlToNHibernateCfg(ISessionFactoryHolder holder, ActiveRecordModelCollection models)\r\n at Castle.ActiveRecord.ActiveRecordStarter.RegisterTypes(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable`1 types, Boolean ignoreProblematicTypes)\r\n at Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource source, Type[] types)\r\n at ConsoleApplication1.Program.Main(String[] args) in c:\\users\\user\\documents\\visual studio 2015\\Projects\\ConsoleApplication1\\ConsoleApplication1\\Program.cs:line 21" 
    TargetSite: {Void AddXmlString(NHibernate.Cfg.Configuration, System.String, Castle.ActiveRecord.Framework.Internal.ActiveRecordModel)} 

回答

1

,让您的域定义你的属性“虚拟”的,这将是这个样子:

这需要通过NHibernate的,以尽自己的懒加载
[ActiveRecord("Student")] 
public class Student : ActiveRecordBase<Student> 
{ 
    [PrimaryKey] 
    public virtual int Id { get; set; } 

    [Property] 
    public virtual string Name { get; set; } 

    [Property] 
    public virtual string Grade { get; set; } 
}  

(活动记录是基于NHibernate的)

看起来更这里:nhibernate and virtual class properties?

而且,如果它不能帮助,可以考虑作为一般的Active Record寻找详细消息(通过提高日志级别)可以告诉你究竟是什么错误

此外,尝试删除“休眠”命名空间从你的app.config活动记录配置你设置MsSql2000Dialect

+0

我给你建议的修改,但没有运气,你正在使用

<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <add key="dialect" value="NHibernate.Dialect.MsSql2000Dialect"/> <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> <add key="connection.connection_string" value="Server=localhost;Database=Art_DEV;Trusted_Connection=True;"/> 

检查MSSQL版本。我仍然收到相同的错误信息。我还更新了有关错误消息详情的问题。 –

+0

@Firoz Ansari,更新了更多信息 – ams4fy

+0

删除“hibernate”命名空间解决了问题。非常感谢您快速解决问题。 –

相关问题