Nhibernate update without select

1,013 views
Skip to first unread message

osman nuri katib

unread,
Aug 9, 2010, 11:51:30 AM8/9/10
to nhu...@googlegroups.com
Hello everybody,
I want to update a persistent record in database(MS sql 2008) and ı dont want to select the record.
 
Is there another way from  "session.CreateSqlQuery()"
 
please help?
 
thanks..

Tuna Toksoz

unread,
Aug 9, 2010, 11:53:42 AM8/9/10
to nhu...@googlegroups.com
executable hql?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

sbohlen

unread,
Aug 9, 2010, 11:56:59 AM8/9/10
to nhusers
You probably want ISession.Load(object id)

ISession.Load(...) returns a proxy of the object that you can then
update but it does NOT actually query the DB to return actual data
first (unlike ISession.Get(...) which first queries the DB to retrieve
the data for the entity).

Google a bit for more info on the difference between .Load(...)
and .Get(...) and you will see examples of this distinction.

HTH,

-Steve B.

osman nuri katib

unread,
Aug 9, 2010, 12:11:35 PM8/9/10
to nhu...@googlegroups.com
what is the "proxy of object"?
does isession.load(..) return an object?
I didn't understand.

2010/8/9 sbohlen <sbo...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Osman Nuri KATİB
       YTÜ
Bilgisayar Mühendisliği

MattO

unread,
Aug 9, 2010, 12:19:19 PM8/9/10
to nhusers
I usually think of a proxy as a placeholder object. Think of it sort
of as declaring your object without setting any values on it.

I believe what steve bohlen then means is you set the values on the
object and the ID and then persist the changes back to the database
and it will only update the record without having to do the select
statement.

I have never seen an example of this though. A question I would have
is how does it know to not set the 15 other propertys on my object
that I didn't want to set.

For instance if your table has 10 fields, and you just want to
ultimate run the following statement: "UPDATE myTable set field1='foo'
where field2='test123'", how does it know to not set the rest of the 8
fields to something?

On Aug 9, 11:11 am, osman nuri katib <osmannurika...@gmail.com> wrote:
> what is the "proxy of object"?
> does isession.load(..) return an object?
> I didn't understand.
>
> 2010/8/9 sbohlen <sboh...@gmail.com>
>
>
>
>
>
> > You probably want ISession.Load(object id)
>
> > ISession.Load(...) returns a proxy of the object that you can then
> > update but it does NOT actually query the DB to return actual data
> > first (unlike ISession.Get(...) which first queries the DB to retrieve
> > the data for the entity).
>
> > Google a bit for more info on the difference between .Load(...)
> > and .Get(...) and you will see examples of this distinction.
>
> > HTH,
>
> > -Steve B.
>
> > On Aug 9, 11:51 am, osman nuri katib <osmannurika...@gmail.com> wrote:
> > > Hello everybody,
> > > I want to update a persistent record in database(MS sql 2008) and ı dont
> > > want to select the record.
>
> > > Is there another way from  "session.CreateSqlQuery()"
>
> > > please help?
>
> > > thanks..
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com­>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Osman Nuri KATİB
>        YTÜ
> Bilgisayar Mühendisliği- Hide quoted text -
>
> - Show quoted text -

osman nuri katib

unread,
Aug 9, 2010, 12:29:42 PM8/9/10
to nhu...@googlegroups.com
Yes Matto,
why do I select 15 column?
I want to set one column which value I am not interested.

Roger Kratz

unread,
Aug 9, 2010, 12:35:30 PM8/9/10
to nhu...@googlegroups.com
session.CreateQuery("update Person p set p.FirstName='something' where id=1").ExecuteUpdate();

Proxies, that's been discussed earlier in this thread will be initialized/loaded when touched the first time.

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för osman nuri katib [osmannu...@gmail.com]
Skickat: den 9 augusti 2010 18:29
Till: nhu...@googlegroups.com
Ämne: Re: [nhusers] Re: Nhibernate update without select

Yes Matto,
why do I select 15 column?
I want to set one column which value I am not interested.

--


You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages