(Asp.Net2.0下使用NHibernate-1.2.0)c# NHibernate配置问题
三省Ta叔 2006-12-19 05:53:58 错误提示:
D:\work\opensource\NHibernateTest\Customer.hbm.xml(2,4): XML validation error: 未能找到元素“urn:nhibernate-mapping-2.0:hibernate-mapping”的架构信息。
基本上按照网上流行的一些教程来配置的,出现这个错误,不知道在配置中那里出了问题,很郁闷。屡试屡败。
现在特需要傻瓜试教程一份。
那为大哥指教下啊!!!谢谢了。
我的基本配置如下:
引用基本的 dll 这个网上都一致
在 Web.config 添加:
<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="Server=localhost;initial catalog=Northwind;Integrated Security=SSPI"/>
</nhibernate>
我的映像 XML 文件: User.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples" table="Users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="identity" />
</id>
<property name="Username" type="string" length="40"/>
<property name="Password" type="string" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
然后自己写了个类,编译成 dll
在Default.aspx.cs 里写操作数据库的代码,比如插入:
protected void Button2_Click(object sender, EventArgs e)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddXmlFile(Server.MapPath("Customer.hbm.xml"));
ISession session = cfg.BuildSessionFactory().OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;
session.Save(newUser);
transaction.Commit();
session.Close();
}
运行,点按钮,这样就出现了 最上面的那错误。
麻烦大家帮帮忙,我刚学这个框架,也准备要用它。在这里先谢谢大家了。