NHibernate 事务查询的更新事件

一个简单的Nhibernate查询,居然有Update事件。

ISessionFactory sessionFactory = cfg.BuildSessionFactory();

using (ISession session = sessionFactory.OpenSession())
{
ITransaction tran = session.BeginTransaction();
Artist a = session.CreateQuery("from Artist")
.SetMaxResults(1)
.List<Artist>()[0];

tran.Commit();

session.Close();
}
Artist类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CopyRightSys.Domain
{
public enum ArtistType
{
其他=0,
歌手=1,
作词=2,
作曲=3

}

public class Artist
{
public virtual int ID { get; set; }
public virtual ArtistType ArtType { get; set; }
public virtual int ArtID { get; set; }

public virtual string Name { get; set; }
public virtual string ShowName { get; set; }
public virtual string ShortName { get; set; }
public virtual string Sex { get; set; }
public virtual string Company { get; set; }
public virtual int SongCount { get; set; }
public virtual DateTime UpTime { get; set; }
public virtual int UpUserID { get; set; }
public virtual string Memo { get; set; }

}
}
查询的SQL:

NHibernate: select TOP (@p0) artist0_.Artor_id as Artor1_0_, artist0_.Artor_type as Artor2_0_, artist0_.Art_ID as Art3_0_, artist0_.Art_Name as Art4_0_, artist0_.Art_ShowName as Art5_0_, artist0_.Art_ShortName as Art6_0_, artist0_.Art_Sex as Art7_0_, artist0_.Art_Company as Art8_0_, artist0_.Art_SongCount as Art9_0_, artist0_.UpTime as UpTime0_, artist0_.UpUser as UpUser0_, artist0_.abstract as abstract0_ from T_artor artist0_;@p0 = 1 [Type: Int32 (0)]

NHibernate: Batch commands:
command 0:UPDATE T_artor SET Artor_type = @p0, Art_ID = @p1, Art_Name = @p2, Art_ShowName = @p3, Art_ShortName = @p4, Art_Sex = @p5, Art_Company = @p6, Art_SongCount = @p7, UpTime = @p8, UpUser = @p9, abstract = @p10 WHERE Artor_id = @p11;@p0 = 歌手 [Type: Int32 (0)], @p1 = 1187 [Type: Int32 (0)], @p2 = '锋崽' [Type: String (100)], @p3 = '锋崽' [Type: String (100)], @p4 = NULL [Type: String (50)], @p5 = NULL [Type: String (50)], @p6 = NULL [Type: String (100)], @p7 = 0 [Type: Int32 (0)], @p8 = 2007-09-30 11:03:23 [Type: DateTime (0)], @p9 = 0 [Type: Int32 (0)], @p10 = NULL [Type: String (200)], @p11 = 1 [Type: Int32 (0)]


1 passed, 0 failed, 0 skipped, took 2.89 seconds (Ad hoc).

很是郁闷呀,查询居然有更新的操作,逐一排查,最后落在了ArtType属性上了,他是枚举类型,再看hbm配置文件

<property name="ArtType" column="Artor_type" type="int" not-null="1"></property>

最后把type="int"去掉,运行,不会在自行update了,估计是数据类型的转换的问题。

NHibernate刚结束不久,好多问题呀。。



 



posted @ 2011-11-09 15:48  db's jim  阅读(294)  评论(0编辑  收藏  举报