我试图在我的项目中运行Nhibernate,但是通过下面的一个错误“No persister for:web.BackEndModel.TeamDetailsDb”是我的解决方案探索。
我的项目层次结构
解决方案:NhibernateClient
项目:网站
folder : BackEndModel File : TeamDetailsDb.cs folder : Controller folder : model folder : view
file:web.hbm.xml
这是我用来保存数据的代码
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
cfg.SetProperty("connection.connection_string", "Data Source=.;Initial Catalog=OPLsite;Integrated Security=True");
//cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
// cfg.AddAssembly("");
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
ITransaction transaction = session.BeginTransaction();
TeamDetailsDb command = new TeamDetailsDb();
command.OwnerName = collection["OwnerName"];
command.TeamName = collection["TeamName"];
session.Save(command);
transaction.Commit();
session.Close();
这是我的web.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="web.BackEndModel.TeamDetailsDb"
assembly="web">
<class name="TeamDetailsDb" table="TeamDetails">
<id name="id" column="id" type="int">
<generator class="identity"></generator>
</id>
<property name="OwnerName" column="OwnerName" type="String"/>
<property name="TeamName" column="TeamName" type="String"/>
<mapping resource="web.hbm.xml" assembly="web" />
</class>
</hibernate-mapping>
这是我的网络配置文件..
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string" value="Data Source=myServer;Initial Catalog=myDatabase;Persist Security Info=True;" />
</nhibernate>
my teamDetailsDb.cs
我对此很新,请帮助我,请becoz我的时间不多了....
答案 0 :(得分:0)
是的,谢谢大家,我发现了它无法正常工作的原因 我改变了
cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
到
cfg.SetProperty("dialect", "NHibernate.Dialect.MsSql2008Dialect");
我也将 Web.hbm.xml 更改为 TeamDetailsDb.hbm.xml
现在我的TeamDetailsDb.hbm.xml是
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="web.BackEndModel"
assembly="web">
<class name="TeamDetailsDb" table="TeamDetails">
<id name="id" column="id" type="int">
<generator class="identity"></generator>
</id>
<property name="OwnerName" column="OwnerName" type="String"/>
<property name="TeamName" column="TeamName" type="String"/>
</class>
</hibernate-mapping>