我是ORM工具的新手。我试着学习NHibernate。我的代码块在下面。
这是员工的映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
assembly="NHiberanate" namespace="NHiberanate.Models">
<class name="Employee" table="tblEmployee" dynamic-update="true" >
<cache usage="read-write"/>
<id name="Id" column="Id" type="int">
<generator class="native" />
</id>
<property name="FirstName" />
<property name="LastName" />
<property name="Designation" />
</class>
</hibernate-mapping>
和nhibernate配置:
<?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="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Server=(local);database=MyTestDB;Integrated Security=SSPI;
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2012Dialect
</property>
</session-factory>
</hibernate-configuration>
我的会话课程:
using NHibernate;
using NHibernate.Cfg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NHiberanate.Models.NHibernate
{
public class OpenNHibertnateSession
{
public static ISession OpenSession()
{
var configuration = new Configuration();
var configurationPath = HttpContext.Current.Server.MapPath
(@"~\Models\Nhibernate\nhibernate.configuration.xml");
configuration.Configure(configurationPath);
var employeeConfigurationFile = HttpContext.Current.Server.MapPath
(@"~\Models\Nhibernate\Employee.mapping.xml");
configuration.AddFile(employeeConfigurationFile);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
return sessionFactory.OpenSession();
}
}
}
和我的模特:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NHiberanate.Models
{
public class Employee
{
public virtual int? Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Designation { get; set; }
}
}
在会话类中,此行有一个错误configuration.AddFile(employeeConfigurationFile);
。它说&#34;无法编译映射文件&#34;。哪里弄错了?