NHibernate: wundersame automatische Updates

by Oliver 27. February 2009 16:48

Kurze Suche, etwas überzogener Artikel (hier), aber die Kerninformation ist wichtig:

Eigene Enumerationen sollten im Mapping-File nicht auf Int gemappt werden, denn ansonsten muss NHibernate die casten und das entsprechende Objekt wird "dirty", was zu dem wundersamen UPDATE führt.

Bei uns z.B. in der Translation-Klasse der Fall:

...
<property name="Type" column="Type" type="int" not-null="true" />
...
<property name="MetaType" column="MetaType" type="int" not-null="true" />
...

 

Stattdessen also immer die Enumeration-Klasse angeben:

...
<property name="Type" column="Type" type="TranslationType" not-null="true" />
...
<property name="MetaType" column="MetaType" type="MetaType" not-null="true" />
...

Jetzt gibt's keine ungewollten UPDATEs mehr. Schön.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.