First of all, this is not an urgent issue.  It's certainly a "nice-to-
have", not an issue at all.  But, I would like some additional
feedback on how others might be solving this "problem".

Below is the original issue submission, followed by a comment on how I
might accomplish what I am looking for.

Something that may not have been clear with the original post, is that
I want my IdConvention to work for classes with table names generated
from the ClassConvention or from an IAutoMappingOverride.


Reported by CamperWill, Apr 15, 2009

What steps will reproduce the problem?
1. Set up implementations of IClassConvention and IIdConvention
2. Convention/pattern for primary key is...  PK_<TableName>Id
3. Add an override (IAutoMappingOverride) for a class specifying a
custom table name

I can apply an override like so:
        public void Override( AutoMap<MyClass> mapping )
        {
            mapping.WithTable( "MyCustomTableName" );
            //would like for the following to be handled by
IIdConvention
            mapping.Id( cp => cp.Id, "PK_MyCustomTableNameId" )
                .GeneratedBy.Sequence( "MyCustomTableNameIdSeq" );
        }

What I would like is for IIdentityPart to have a reference to the
generated TableName (or the IClassMap).  Then I wouldn't have to
override the Id and Sequence mapping:

    public class PrimaryKeyConvention : IIdConvention
    {
        ...

        public void Apply( IIdentityPart target )
        {
            target.ColumnName( "PK_" + target.TableName + "Id" );
            target.GeneratedBy.Sequence( target.TableName + "IdSeq" );
        }
    }

What version of the product are you using? On what operating system?
 - latest source as of Apr 10, 2009.




Comment 1 by Hudson.Akridge, Apr 25 (47 hours ago)

I don't believe that the problem is an id not referencing the table
name, because that makes sense. You don't know exactly in what order
the conventions are going to be applied in, so it's possible that your
mapping.WithTable() won't fire before your ID convention comes up.

How you're solving it in your top code block is the proper way to do
it. If you wanted to separate it out, then what you'll need to do, is
create a way for the IdConvention to access the table name outside of
Fluent, such as storing it as a static in a class somewhere, or, what
I've done in my project is I have a class that I use to generate all
of my table/ID/FK names just by passing it type constants. i.e.

GetTableName<Order>() returns me "Orders". GetIdName<Order>() returns
me "OrderID". Those are static methods that are available through a
helper class to all of my conventions. Then my IdConvention calls that
in the places that you've got "target.TableName".

Marking the issue as Won't Fix for now. If you feel like you disagree,
please bring it up on the group mailing list so we can get some more
people involved in a discussion and see what the general consensus
is. :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to