Reputation: 953
I've got a User class that I want to update. There's a User table in my database with two columns among others: FirstName and Lastname and there's a computed column called DisplayName that concatenates the two with a space in the middle. The NHibernate mapping for DisplayName is
<property name="DisplayName" type="string" generated="always"/>
When I update the User object and commit the transaction, NHibernate runs an extra select statement just on the DisplayName property, I presume to keep the object and the DB row in sync. I don't need that as the object goes out of scope right afterwards.
Is there something I can do to tell NHibernate that there's no need to get the updated DisplayName at this time?
Regards, F.
Upvotes: 2
Views: 1248
Reputation: 2090
Replace generated="always"
with insert="false" update="false"
. It will disable inserts and updates to this column and will not make an extra select statement to refresh the value.
Upvotes: 0
Reputation: 52725
generated="always"
means exactly that: "this is a value generated by the DB every time I modify this row; please refresh it for me".
NH does not have a concept like "only refresh this if a particular column changed".
My opinion is that you should generate that value in your domain model instead of the DB.
Upvotes: 2