Я пытаюсь использовать этот учебник: Привет NHibernate
Это мой файл конфигурации NHibernate:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<reflection-optimizer use="false"/>
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS; Initial Catalog=dbTest; Trusted_Connection=true;</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>
<mapping resource="TestNHibernate.user.hbm.xml" assembly="TestNHibernate"/>
</session-factory>
</hibernate-configuration></configuration>
Это мой файл сопоставления:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TestNHibernate"
namespace="TestNHibernate">
<class name="user" table="user">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name" />
</class>
</hibernate-mapping>
Пользователь класса:
class user
{
public virtual int Id { get;set; }
public virtual string Name { get; set; }
}
и вот код запроса:
Configuration config = new Configuration();
config.AddAssembly(typeof(user).Assembly);
ISessionFactory sessionFactory = config.BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
{
IQuery query = session.CreateQuery("from user as u");
IList<user> lst = query.List<user>();
foreach (var user in lst)
{
Console.WriteLine(user.Name);
}
}
Всегда отображается ошибка:
не удалось выполнить запрос[выберите user0_.Id как Id0_, user0_.Name как Name0_ от пользователя user0_] [SQL: выберите user0_.Id as Id0_, user0_.Name как Name0_ от пользователя user0 _]
Я пытался вставитьобновить, но это также шоу не может вставить, обновить.Где моя проблема?
Есть ли файл сопоставления?Пожалуйста, дайте мне совет!Спасибо!