菜鳥問NHibernate問題﹐尋求高手解決。
在測試類中做了下面的動作﹕
ISession s = SessionFactory.OpenSession();
ITransaction t = s.BeginTransaction();
try
{
s.Save(entity);
t.Commit();
}
catch(Exception e)
{
t.Rollback();
throw e;
}
finally
{
s.Close();
}
用NUnit測試﹐顯示sql語句怎么是這樣的呢﹐先刪除我的表﹐再建表﹐再新增。怎么是這樣的呢。暈
drop table G_users
drop table G_guestbook
create table G_users (
id INT IDENTITY NOT NULL,
name NVARCHAR(20) null,
email NVARCHAR(40) null,
password NVARCHAR(20) null,
flag INT null,
regtime DATETIME null,
primary key (id)
)
create table G_guestbook (
id INT IDENTITY NOT NULL,
userid INT null,
username NVARCHAR(20) null,
title NVARCHAR(100) null,
article NVARCHAR(255) null,
pubtime DATETIME null,
primary key (id)
)
NHibernate :INSERT INTO G_users (email, name, regtime, password, flag) VALUES (@p0, @p1, @p2, @p3, @p4); select SCOPE_IDENTITY()
posted @ 2006-05-25 14:36 karlsoft 阅读(204) 评论(0)
编辑
使用NHibernate在Web層在按鈕下實現這個﹐不能添加數據﹐請問什么原因﹐是不是配置文件有問題﹐在web.config中已經加了這個
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System,Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
也加了這個
<nhibernate>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
<add key="hibernate.connection.connection_string" value="server=MIS03;uid=sa;pwd=;"/>
</nhibernate>
我的代碼碼如下﹕
按鈕下實現如下:
Configuration cfg = new Configuration();
cfg.AddAssembly("GuestBook.Data");
ISessionFactory f = cfg.BuildSessionFactory();
ISession s = f.OpenSession();
ITransaction t = s.BeginTransaction();
Users newUser = new Users();
newUser.Name = "papersnake";
newUser.Password = "123456";
newUser.Email = "you@hotmail.com";
newUser.RegTime = DateTime.Now;
s.Save(newUser);
t.Commit();
s.Close();
posted @ 2006-05-25 12:11 karlsoft 阅读(309) 评论(2)
编辑