Welcome :)

When in doubt, throw implementation stuff (like Id and Version) on the base
class for everything and forget about it :)

On Mon, Jan 18, 2010 at 11:42 AM, Jeff Doolittle <[email protected]>wrote:

> Thanks Hudson, that makes total sense.  I'm pretty satisfied already
> since the latest build fixes the base-entity version problem.  I can
> probably live with one extra property on my entities since I've been
> able to move most of the auditing properties to my component class.
>
> --Jeff
>
>
> On Jan 18, 9:39 am, Hudson Akridge <[email protected]> wrote:
> > > What I'd really like to do is put my version property on a component
> > > class.
> >
> > That's an NH thing, not specifically a FNH thing. Head over to nhusers
> and
> > they might be able to help you out a bit more. But this sort of thing I'm
> > almost positive isn't possible. Your audit columns are business enforced,
> > and so you can use a business aware mapping to enforce them (such as
> using a
> > component, or heck, even a collection for an audit log on each entity if
> you
> > wanted), however <version> is a very specific NH tag and must be applied
> to
> > the entity it's versioning directly, and thus, on the class itself
> > somewhere. Just like an Id.
> >
> > Now, what you might look into is private/protecting that version property
> in
> > your application, then using FNH's Reveal static method to get at the
> > private property. That way your API remains free of a version member for
> > other classes interacting with your class.
> >
> > On Mon, Jan 18, 2010 at 11:13 AM, Jeff Doolittle <
> [email protected]>wrote:
> >
> > > I downloaded the latest build (614) and I was able to add a Version
> > > property to a base class, as described by Paul Batum.
> >
> > > I'd like to add another wrinkle to the mix.
> >
> > > What I'd really like to do is put my version property on a component
> > > class.  I already have a component class for audit columns like
> > > LastModified, CreatedBy, etc.  This keeps the surface area of my
> > > entities clean when I'm using them throughout the application.  I
> > > don't always want to see these properties when I'm typically working
> > > with my entities and putting them on a component class keeps them off
> > > the main surface area of my entities.  The Version column also fits
> > > this paradigm.  I'm not going to use it directly, so I'd like to get
> > > it out of the way and putting it on a component would do the trick.
> > > However, when I try doing this, there is no column generated by Fluent
> > > NHibernate for the Version property of the component class.  My other
> > > audit columns are generated, but the Version column completely
> > > disappears.
> >
> > > --Jeff
> >
> > > On Jan 18, 3:53 am, Jon <[email protected]> wrote:
> > > > Is anyone else still having this issue, or is it just me? It's
> exactly
> > > > as Neal describes - when I have the Version property in the base
> class
> > > > it doesn't work, and when it's in the subclass it works fine. As
> > > > Deesky says, having to create an override for every entity class
> seems
> > > > to defeat the point of having the base class, so I'd rather avoid
> > > > that.
> >
> > > > @Paul Batum, what version of FNH are you using? I have 1.0.0.594.
> >
> > > > Cheers
> > > > Jon
> >
> > > > On 6 Jan, 22:14, Paul Batum <[email protected]> wrote:
> >
> > > > > My understanding is that this is fixed. I'm using an automapped
> base
> > > > > class with aVersionproperty and it works fine.
> >
> > > > > On Thu, Jan 7, 2010 at 7:51 AM, Jeff Doolittle <
> > > [email protected]> wrote:
> > > > > > Does anyone know if a fix for this if forthcoming?
> >
> > > > > > --Jeff
> >
> > > > > > On Nov 13 2009, 10:18 am, Billy <[email protected]>
> > > wrote:
> > > > > >> I agree with Deeksy.  Theversionproperty from a superclass was
> > > > > >> mapping automatically previously.  Seems to require a manual
> mapping
> > > > > >> now or it gets completely ignored.
> >
> > > > > >> Billy
> >
> > > > > >> On Nov 5, 10:58 pm, Deeksy <[email protected]> wrote:
> >
> > > > > >> > This seems to be a bug introduced in (or some time before) 1.0
> > > RTM.  I
> > > > > >> > was using a previousversionand theVersionproperty in the base
> > > > > >> > class was being set up as a <version> in the mapping file.
> >
> > > > > >> > Creating an AutoMappingOverride for each class defeats the
> point
> > > of
> > > > > >> > having theVersioncolumn in the base class in the first place.
> >
> > > > > >> > The property is of type int, and it gets picked up by fluent
> if
> > > it's
> > > > > >> > called something else (like Versionx), but when it's
> > > calledVersionit
> > > > > >> > just gets ignored (not added as a column either).
> >
> > > > > >> > On Oct 27, 10:43 am, Neal Blomfield <[email protected]
> >
> > > wrote:
> >
> > > > > >> > > Chanan,
> >
> > > > > >> > > you need to create an IAutoMappingOverride for each mapped
> type,
> > > these
> > > > > >> > > look something like:
> >
> > > > > >> > >     public class QuestionAutoMapOverride :
> > > > > >> > > IAutoMappingOverride<Question>
> > > > > >> > >     {
> > > > > >> > >         public void Override( AutoMapping<Question> mapping
> )
> > > > > >> > >         {
> > > > > >> > >             mapping.Version( question => question.Version)
> > > > > >> > >                 .UnsavedValue( "0" );
> > > > > >> > >         }
> > > > > >> > >     }
> >
> > > > > >> > > and then you need to tell the auto mapper to use the
> overrides -
> > > I use
> > > > > >> > > the UseOverridesFromAssemblyOf<> to achieve this (not sure
> if
> > > there
> > > > > >> > > are other approaches ):
> >
> > > > > >> > > AutoMap
> > > > > >> > >   .AssemblyOf<Entity>()
> > > > > >> > >   .Where( type => typeof(Entity).IsAssignableFrom(type) )
> > > > > >> > >   IgnoreBase<Entity>()
> > > > > >> > >   .IgnoreBase( typeof(Entity<>) )
> > > > > >> > >   .Conventions.Setup( ConfigureConventions )
> > > > > >> > >   .UseOverridesFromAssemblyOf<DomainMapper>();
> >
> > > > > >> > > On Oct 21, 8:59 am, Chanan <[email protected]> wrote:
> >
> > > > > >> > > > Hi Neal,
> >
> > > > > >> > > > I just found the same problem...Versionseems to only wotk
> when
> > > > > >> > > > declared in the Entity class and does not when declared in
> the
> > > Base
> > > > > >> > > > Class.
> >
> > > > > >> > > > By the way, would you be so kind as to post your Mapping
> > > override
> > > > > >> > > > code, its been a long day... :)
> >
> > > > > >> > > > Thanks,
> > > > > >> > > > Chanan.
> >
> > > > > >> > > > On Oct 18, 7:30 pm, Neal Blomfield <
> [email protected]>
> > > wrote:
> >
> > > > > >> > > > > I have an entity base class that looks as follows:
> >
> > > > > >> > > > >     public abstract class Entity : IEquatable<Entity>
> > > > > >> > > > >     {
> > > > > >> > > > >         public Guid Id { get; private set; }
> > > > > >> > > > >         public longVersion{ get; protected set; }
> >
> > > > > >> > > > >         protected Entity()
> > > > > >> > > > >         {
> > > > > >> > > > >             Id = GenerateComb();
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         public override string ToString()
> > > > > >> > > > >         {
> > > > > >> > > > >             // ... elided for brevity
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         public override bool Equals( object obj )
> > > > > >> > > > >         {
> > > > > >> > > > >             return Equals( obj as Entity );
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         public bool Equals( Entity other )
> > > > > >> > > > >         {
> > > > > >> > > > >             if (other == null)
> > > > > >> > > > >             {
> > > > > >> > > > >                 return false;
> > > > > >> > > > >             }
> >
> > > > > >> > > > >             if (ReferenceEquals(other, this))
> > > > > >> > > > >             {
> > > > > >> > > > >                 return true;
> > > > > >> > > > >             }
> >
> > > > > >> > > > >             if (GetType() != other.GetType())
> > > > > >> > > > >             {
> > > > > >> > > > >                 return false;
> > > > > >> > > > >             }
> >
> > > > > >> > > > >             return InternalEquals(other);
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         protected virtual bool InternalEquals( Entity
> other
> > > )
> > > > > >> > > > >         {
> > > > > >> > > > >             // ... elided for brevity
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         public override int GetHashCode()
> > > > > >> > > > >         {
> > > > > >> > > > >             // ... elided for brevity
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         protected virtual object[]
> > > GetSignaturePropertyValues()
> > > > > >> > > > >         {
> > > > > >> > > > >             return new object[]{Id,Version};
> > > > > >> > > > >         }
> >
> > > > > >> > > > >         private Guid GenerateComb()
> > > > > >> > > > >         {
> > > > > >> > > > >             // ... elided for brevity ( but its based on
> the
> > > NH /
> > > > > >> > > > > Jimmy Nilsson implementation )
> > > > > >> > > > >         }
> > > > > >> > > > >     }
> >
> > > > > >> > > > >     public abstract class Entity<T> : Entity,
> IEquatable<T>
> > > where T :
> > > > > >> > > > > Entity<T>
> > > > > >> > > > >     {
> > > > > >> > > > >         public virtual bool Equals( T other )
> > > > > >> > > > >         {
> > > > > >> > > > >             return base.Equals( other );
> > > > > >> > > > >         }
> > > > > >> > > > >     }
> >
> > > > > >> > > > > All entities inherit from Entity<T>.
> >
> > > > > >> > > > > This is automapped via:
> >
> > > > > >> > > > > AutoMap
> > > > > >> > > > > .AssemblyOf<Entity>()
> > > > > >> > > > > .Where( type => typeof( Entity ).IsAssignableFrom( type
> ) )
> > > > > >> > > > > .IgnoreBase<Entity>()
> > > > > >> > > > > .IgnoreBase( typeof( Entity<> ) );
> >
> > > > > >> > > > > With this setup, theVersionproperty in the Entity base
> class
> > > is not
> > > > > >> > > > > being mapped ( noVersioncolumn is being created at all
> ).  I
> > > have
> > > > > >> > > > > checked that FNH can see the property by changing it to
> > > VersionX and
> > > > > >> > > > > checking it was mapped ( which it was ), I have also (
> while
> > > > > >> > > > > Entity.Versionwas renamed Entity.VersionX ) added
> > > aVersionproperty
> > > > > >> > > > > to one of my entities directly ( i.e. I had a property
> > > declared as
> > > > > >> > > > > Account.Version) and this worked as expected.
> >
> > > > > >> > > > > Any ideas why Entity.Versionis not being mapped as I am
> at a
> > > complete
> > > > > >> > > > > loss as to why this is happening ( currently I must
> > > explicitly map it
> > > > > >> > > > > with an automapping override ) =(- Hide quoted text -
> >
> > > > > >> > > - Show quoted text -
> >
> > > > > > --
> > > > > > 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]<fluent-nhibernate%[email protected]>
> <fluent-nhibernate%[email protected]<fluent-nhibernate%[email protected]>
> >
> > > .
> > > > > > For more options, visit this group athttp://
> > > groups.google.com/group/fluent-nhibernate?hl=en.
> >
> > > --
> >
> > ...
> >
> > read more ยป
>
> --
> 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]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge
--
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