Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Partial Update

Tags:

nhibernate

Is there a way in NHibernate to start with an unproxied model

var m = new Model() { ID = 1 };
m.Name = "test";
//Model also has .LastName and .Age

Now save this model only updating Name without first selecting the model from the session?

like image 835
bleevo Avatar asked Aug 17 '09 00:08

bleevo


1 Answers

If model has other properties then name, you need to initialize these with the original value in the database, unless they will be set to null.

You can use HQL update operations; I never tried it myself.

You could also use a native SQL statement. ("Update model set name ...").

Usually, this optimization is not needed. There are really rare cases where you need to avoid selecting the data, so writing this SQL statements are just a waste of time. You are using an ORM, this means: write your software object oriented! Unless you won't get much advantages from it.

like image 117
Stefan Steinegger Avatar answered Sep 24 '22 19:09

Stefan Steinegger