Cool stuff. I think it's good enough to reflect a dirty state if any
property as been modified (even if it has been changed back to its
original value).
I'm still a little unclear. Once this has been done, I'm thinking I
should register an event handler on the object and then, if called,
assume the record is dirty, correct?
I really wish there would be a way to call an object at any level of a
system with a call to something like object.IsDirty(). Perhaps I could
use this same method to add my own custom interface that allows me to
call a IsDirty() type of function on an object.
I'm very new to NHibernate, so I'm not sure how to get to the current
and previous state values (I'm doing my own custom dirty checking via
an interceptor, so something along those lines would be great).
Something like:
interface IDirty
{
Dirty
{
get;
}
}
MyObject : IDirty
{
Dirty
{
get
{
// Compare currentstate values against previousstate values. Not
sure how
// I can access these from within an object. Can this only be
done externally
// via proxies?
}
}
}
Here's another real newbie question that I'm unclear about. Assume
I've mapped two objects, A and B. A has a one-to-many relationship
mapped to A and B has a many-to-one relationship mapped to A.
Currently, I have to explicitly set the owner of B in order for it to
save correctly when adding it to A's collection. I'm wondering if this
relationship can be fixed up automatically.
For example:
A currentInstance = GetCurrentA();
B createdObject = new B();
createdObject.Owner = currentInstance; // This line is necessary with
my current mapping.
IList<B> tempList = currentInstance.OwnedBs;
tempList.Add( createdObject ); // Can NHibernate infer the Owner from
adding it to this list?
Session.Save( currentInstance ); // Works great. But would like the
extra fixup removed.
Thanks again in advance!
Travis
On Jun 14, 10:28 am, "James Kovacs" <
jkov...@post.harvard.edu> wrote:
> That is a nice way to implement INotifyPropertyChanged. The only issue is
> that it only tells you if the property has changed, not if the entity is
> dirty. For example, assuming your implementation:
>
> IFoo foo = session.Get<Foo>(42); // value of foo.Bar is 1
> foo.Bar = 10;
> foo.Bar = 1;
>
> You will get 2 property changed notifications, as expected. Is the entity
> dirty? No, because you changed the value back to the original value.
>
> If this scenario is important to your business users (i.e. you need to know
> whether a save is really required versus potentially required), then you
> could write a different interceptor that would create a dirty-checking proxy
> that compared current entity state to what is in NHibernate's level 1 cache.
>
> James
> --
> James Kovacs, B.Sc., M.Sc., MCSD, MCT
> Microsoft MVP - C# Architecturehttp://
www.jameskovacs.com
>
jkov...@post.harvard.edu
> > www.*ayende*
> > .com/Blog/archive/2007/04/17/Advance-Extending-NHibernate-Proxies.aspx