http://fabiomaulo.blogspot.com/2008/10/how-test-your-mappings-ghostbuster.html

2009/2/26 zhibin <[email protected]>

>
> Hi,
>
> I am a new user of NHibernate, it plus FluentNHibernate impress me
> very much, thanks for this great product.
>
> When I test the following testing code,
>
>            Contact c;
>            using (ISession s = sessionFactory.OpenSession())
>            using (ITransaction t = s.BeginTransaction())
>            {
>                c = s.CreateCriteria(typeof(Contact)).Add
> (Restrictions.Eq("UserName", "ab")).UniqueResult<Contact>();
>                t.Commit();
>            }
>
> it will always generate two sql statement:
>
> NHibernate: SELECT this_.Id as Id0_0_, this_.FirstName as
> FirstName0_0_, this_.UserName as UserName0_0_, this_.Role as Role0_0_,
> this_.LastName as LastName0_0_, this_.CreateDate as CreateDate0_0_,
> this_.DateOfBirth as DateOfBi7_0_0_, this_.Email as Email0_0_,
> this_.Title as Title0_0_, this_.Notes as Notes0_0_,
> this_.Organization_id as Organiz11_0_0_ FROM "Contact" this_ WHERE
> this_.UserName = :p0; :p0 = 'ab'
>
> NHibernate: UPDATE "Contact" SET FirstName = :p0, UserName = :p1, Role
> = :p2, LastName = :p3, CreateDate = :p4, DateOfBirth = :p5, Email
> = :p6, Title = :p7, Notes = :p8, Organization_id = :p9 WHERE Id
> = :p10; :p0 = '', :p1 = 'ab', :p2 = 'Customer', :p3 = '', :p4 =
> '2009-2-26 9:56:36', :p5 = '', :p6 = '', :p7 = 'developer', :p8 =
> '', :p9 = '4', :p10 = '9'
>
> I feel very confused since the variable "c" have not been modified
> within the transaction, why an update statement will be executed?
>
> I tried to comment out the transaction lines:
>            Contact c;
>            using (ISession s = sessionFactory.OpenSession())
>            // using (ITransaction t = s.BeginTransaction())
>            {
>                c = s.CreateCriteria(typeof(Contact)).Add
> (Restrictions.Eq("UserName", "ab")).UniqueResult<Contact>();
>                // t.Commit();
>            }
>
> Then no update statement be generated.
>
> Is it the normal behaviour?  Or I made some mistakes otherwise?
>
> Thanks in advance,
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to