я в проекте простое подключение к базе данных:Как подключить nhibernate к локальному SQLEXPRESS?
public static string GetConnectionString()
{
return @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + HttpContext.Current.Request.PhysicalApplicationPath + "Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
}
Теперь я пытаюсь реализовать NHibernate проекта.
hibernate.cfg.xml здесь:
<?xml version="1.0" encoding="utf-8"?>
<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="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Desktop\Application+\Application\Application.mdf;Integrated Security=True;User Instance=True</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Тестовые класс "Клиенты" объект здесь:
public class Clients
{
private Guid id;
private string name;
private string phone;
private string fax;
private string email;
private string address;
private string contactPerson;
public virtual Guid Id
{
get { return id; }
set { id = value; }
}
public virtual string Phone
{
get { return phone; }
set { phone = value; }
}
public virtual string Fax
{
get { return fax; }
set { fax = value; }
}
public virtual string Email
{
get { return email; }
set { email = value; }
}
public virtual string Address
{
get { return address; }
set { address = value; }
}
public virtual string ContactPerson
{
get { return contactPerson; }
set { contactPerson = value; }
}
public virtual string Name
{
get { return name; }
set { name = value; }
}
}
Clients.hbm.xml здесь:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="WrapperObjects" namespace="WrapperObjects">
<class name="Clients" table="Clients" lazy="false">
<id name="Id" column="id">
<generator class="native"></generator>
</id>
<property name="Name" column="name" type="System.String"/>
<property name="Phone" column="phone" type="System.String"/>
<property name="Fax" column="fax" type="System.String"/>
<property name="Email" column="email" type="System.String"/>
<property name="Address" column="address" type="System.String"/>
<property name="ContactPerson" column="contactPerson" type="System.String"/>
</class>
</hibernate-mapping>
Я использовал его например:
public static void Configure()
{
sessions = new Configuration().Configure().AddClass(typeof(Clients)).BuildSessionFactory();
}
public static void Insert(Clients pb)
{
using (ISession session = sessions.OpenSession())
using (ITransaction tx = session.BeginTransaction())
{
session.Save(pb);
tx.Commit();
}
}
На Configure() метод появляется сообщение об ошибке: Ключевое слово не supported.Parameter имя: attachdbfilename Как исправить ??))