Maybe this can help you in some way, as I run into kinda similar
problem

http://forum.hibernate.org/viewtopic.php?t=992593&highlight=proxy+reference

On Apr 1, 3:24 pm, jakescott <[email protected]> wrote:
> Hi Jon inheriting from the fluent Entity class does not solve the
> problem out of the box.
>
> The problem is:
>
>         public override bool Equals(object obj)
>         {
>             if (ReferenceEquals(null, obj)) return false;
>             if (ReferenceEquals(this, obj)) return true;
>             if (GetType() != obj.GetType()) return false; // this line
> always evaluates to false because the type of obj.GetType() is the
> proxy object eg StoreProxy6c0bc5809d5049799f62c7a4c08f45de
>             return Equals((Entity) obj);
>         }
>
> If I comment out those lines then the tests pass. Here is a link to
> the working testhttp://pastie.org/434198
>
> So I guess my question now is what is the best way to solve this
> problem? Change the Entities Equals method or pass in a test
> IEqualityComparer into the PersistanceSpecification?
>
> On Apr 2, 1:18 am, Jon Kruger <[email protected]> wrote:
>
> > I've had the same problem before.  One way to get around this is to pass an
> > IEqualityComparer into the PersistenceSpecification constructor, and then in
> > there you can compare that the two Store objects are equal.
>
> > The other thing you can do is override Equals() on your entity objects and
> > have Equals() return true if the objects are of the same entity type and the
> > Ids are the same.  If you derive all of your entity classes from
> > FluentNHibernate.Data.Entity you will get all of this for free.  (I think
> > this should work, I haven't actually tried it yet.)
>
> > Jon
>
> > On Wed, Apr 1, 2009 at 1:30 AM, jakescott <[email protected]> wrote:
>
> > > Just wondering if I am doing something wrong here. I am trying to run
> > > an integration test based on the example code on the wiki and example
> > > application. Hoping somebody can help me out :)
>
> > > I have saved the example code here:
>
> > >http://pastie.org/433518
>
> > > var store = new Store { Name = "Bakery" };
>
> > > new PersistenceSpecification<Employee>(session)
> > > .CheckProperty(x => x.FirstName, "Jake")
> > > .CheckProperty(x => x.LastName, "Scott")
> > > .CheckReference(x => x.Store, store)
> > > .VerifyTheMappings();
>
> > > System.ApplicationException: Expected 'fluent_muck_around.Store' but
> > > got 'StoreProxy4a9aef614d8e4f91a1329920a5592084' for Property 'Store'
> > > at
>
> > > FluentNHibernate.Testing.PersistenceSpecification`1.PropertyValue.CheckValu
> > >  e
> > > (Object target) in C:\mvc\fluent-nhibernate\src\FluentNHibernate
> > > \Testing\PersistenceSpecification.cs: line 265
> > > at
>
> > > FluentNHibernate.Testing.PersistenceSpecification`1.<>c__DisplayClass2.<Ver
> > >  ifyTheMappings>b__1
> > > (PropertyValue p) in C:\mvc\fluent-nhibernate\src\FluentNHibernate
> > > \Testing\PersistenceSpecification.cs: line 119
> > > at System.Collections.Generic.List`1.ForEach(Action`1 action)
> > > at
> > > FluentNHibernate.Testing.PersistenceSpecification`1.VerifyTheMappings
> > > () in C:\mvc\fluent-nhibernate\src\FluentNHibernate\Testing
> > > \PersistenceSpecification.cs: line 119
> > > at
>
> > > fluent_muck_around.IntegrationTests.should_save_and_load_an_employee_with_a
> > >  _store_reference
> > > () in Entities.cs: line 134
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to