我试图在我的项目中运行 Nhibernate,但它通过一个错误“没有持久性:web.BackEndModel.TeamDetailsDb”是我的解决方案探索。
我的项目层次结构
解决方案:NhibernateClient
项目:网络
folder : BackEndModel File : TeamDetailsDb.cs folder : Controller folder : model folder : view
文件: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>
我的团队DetailsDb.cs
我对此很陌生,请帮助我,请因为我的时间不多了....