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>
ローカルには、3 つのテーブルを持つ非常に単純なデータベースDemoDBがあり、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(会社), typeof(部署), typeof(従業員)); IList employees = Employee.FindAllByProperty("FirstName", firstName);
エラーが発生します:
NHibernate.HibernateException : 名前付き接続文字列が見つかりません サーバー=(ローカル);初期カタログ=DemoDB;統合セキュリティ=SSPI
接続の何が問題になっていますか?