Brian Hartsock's Blog

NHibernate CodeCamp Talk – Source Code

by bhartsock on Oct.04, 2009, under Uncategorized

I have published the source of my Code Camp talk here. Check it out and post any questions.

Thanks to everyone who showed up for the NHibernate talk. It went really well and everyone had tons of great questions. Feel free to post feedback here, both positive and negative, so the next time I give this talk, it will be even better.

For those of you that just want a little more guidance on NHibernate, here are some good links:

Also, thanks to the coordinators of Richmond CC. I had a great time.

Post to Twitter Post to Digg Post to Facebook Post to Reddit

:, , ,

5 Comments for this entry

  • Brian O'Neil

    Thanks for the great talk on NHibernate at Richmond!

    I have a followup question. It appears to me that NHibernate is setting “IsChanged” equal to True upon a call to “List”. As you may expect this renders that property useless for change tracking. From my experience with CSLA, there is usually a way to tell if the property is being changed during Load or upon a user of the object actually changing something. “Dirty” was never the case after a “Fetch” from the database, because a local variable was set for each column, not using the public Setter method.

    Do you see this same behavior?

    Thanks again,
    Brian

  • bhartsock

    Do have some sample source code I could look at, maybe a small piece or some psuedo code. If I could see the code, the query, and the mappings, I might be able to help a little bit.

  • Brian O'Neil

    Sure… here is a chunk of the entity (created by MyGeneration) where you can how IsChanged is effected by the public property setter:

    public virtual string EmployerName
    {
    get { return _employerName; }
    set { _isChanged |= (_employerName != value); _employerName = value; }
    }

    Mapping of that column is really irrelevant, but here it is for context :

    @lt;property type=”string” length=”50″ name=”EmployerName” column=”`EmployerName`” /@gt;

    A quick way to see what is happening, is just set a breakpoint in one of your entities public setters and call List@lt;@gt; on it.

    Thanks again

  • bhartsock

    That’s because NHibernate uses the setter to set the value. It is possible to change this behavior though.

    http://nhforge.org/doc/nh/en/index.html#mapping-declaration-property

    Read the access/naming strategies section. This will tell NHibernate how to access the property.

    <property name=”EmployerName” access=”nosetter.camelcase-underscore” />

    This will tell NHibernate, don’t use the setter, instead use the field that is the camel-cased version of the property name, prefixed with an underscore.

    Make sense? It’s a weird syntax, but it works like a charm.

  • Brian O'Neil

    Thanks so much! I would have never thought the mapping was at work here. I should have listened better.
    All good now.

Leave a Reply

Post by day

October 2009
M T W T F S S
« Sep   Nov »
 1234
567891011
12131415161718
19202122232425
262728293031