マッピングファイルのどこに問題があるか知っていますか?
Eroor: マッピング ドキュメントをコンパイルできませんでした: NHibernateTutorial.Mapping.Character.hbm.xml
すべてのファイルを追加します。
キャラクター
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NHibernateTutorial.Domain
{
public class Character
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual int HealthPoints { get; set; }
public virtual int Mana { get; set; }
public virtual string Profession { get; set; }
}
}
マッピング ( Character.hbm.xml )
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateTutorial"
namespace="NHibernateTutorial.Domain">
<class name="Character">
<id name="Id">
<generator class="guid" />
</id>
<property name="Name" />
<property name="HealthPoints" />
<property name="Mana" />
<property name="Profession" />
</class>
</hibernate-mapping>
エラー
接続文字列
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Database=rafal;Trusted_Connection=True;</property>
</session-factory>
</hibernate-configuration>
HibernateHelper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernateTutorial.Domain;
namespace NHibernateTutorial
{
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
var configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(typeof(Character).Assembly);
_sessionFactory = configuration.BuildSessionFactory();
}
return _sessionFactory;
}
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
}
キャラクターリポジトリ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernateTutorial.Domain;
using NHibernate;
namespace NHibernateTutorial
{
public class CharacterRepository
{
public void Add(Character newCharacter)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(newCharacter);
transaction.Commit();
}
}
}
public Character GetCharacterByName(string name)
{
using (ISession session = NHibernateHelper.OpenSession())
{
var result = session.QueryOver<Character>().Where(x => x.Name == name).SingleOrDefault();
return result ?? new Character();
}
}
public void Update(Character newCharacter)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Update(newCharacter);
transaction.Commit();
}
}
}
public void Delete(Character newCharacter)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete(newCharacter);
transaction.Commit();
}
}
}
}
}
例外の詳細: