【发布时间】:2013-07-26 11:40:42
【问题描述】:
我想尝试一个使用 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 { [活动记录] 公共类员工:ActiveRecordBase { [首要的关键] 公共 int ID { 获取;放; }
[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(公司),typeof(部门),typeof(员工)); IList 员工 = Employee.FindAllByProperty("FirstName", 名字);
我收到一个错误:
NHibernate.HibernateException:找不到命名的连接字符串 服务器=(本地);初始目录=DemoDB;集成安全=SSPI
连接出了什么问题?
【问题讨论】:
标签: c# activerecord