我想尝试一个使用 Active Record + MSSQL2012 的简单示例。这是我的 App.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<startup>
</startup>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect, NHibernate</property>
<property name="connection.connection_string_name">Server=(local);initial catalog=DemoDB;Integrated Security=SSPI</property>
</session-factory>
</hibernate-configuration>
</configuration>
在本地,我有一个非常简单的数据库DemoDB,有 3 个表,如果通过 SQL Management Studio 连接到。
员工等级:
使用 Castle.ActiveRecord;
命名空间 ActiveRecordDemo.Domain { [ActiveRecord] public class Employee : ActiveRecordBase { [PrimaryKey] public int Id { get; 放; }
[Property] public string FirstName { get; set; } [Property] public string LastName { get; set; } [BelongsTo(Type = typeof(Department), Column = "Id")] public Department Department { get; set; } } }
当我运行代码时
ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance, typeof(Company), typeof(Department), typeof(Employee)); IList 员工 = Employee.FindAllByProperty("FirstName", firstName);
我收到一个错误:
NHibernate.HibernateException : 找不到命名连接字符串 Server=(local);initial catalog=DemoDB;Integrated Security=SSPI
连接有什么问题?