That could very well be it. In the version you're using we do override
what's written in mappings, so you'll need to modify the Accept method. For
1.0 this decision will be reversed.

On Tue, Aug 11, 2009 at 3:46 PM, Chris Fazeli <[email protected]> wrote:

>
> Can S#arp's HasManyConvention be messing with this?
>
> public class HasManyConvention : IHasManyConvention
>    {
>        public bool Accept(IOneToManyPart oneToManyPart)
>        {
>            return true;
>        }
>
>        public void Apply(IOneToManyPart oneToManyPart)
>        {
>            oneToManyPart.KeyColumnNames.Clear();
>            oneToManyPart.KeyColumnNames.Add
> (oneToManyPart.EntityType.Name + "Fk");
>        }
>    }
>
> ?? I've read this before on the forums but I don't remember...
> conventions are run before or after automapping overrides? Even still,
> you wouldn't overwrite previously written mappings anyway right?
>
> On Aug 11, 10:40 am, Chris Fazeli <[email protected]> wrote:
> > The Business entity is automapped, but I use an override to handle
> > several desired changes, such as cascading, and many-to-many mapping.
> > Since the HasMany wasn't getting automapped correctly, I tried to
> > override it, but still no luck.
> >
> > public class BusinessMap : IAutoMappingOverride<Business> {
> >   public void Override(AutoMap<Business> mapping) {
> >     mapping.JoinedSubClass<Manager>("BusinessId")
> >                 .HasManyToMany<Customer>(x => x.Customer)
> >                 ... // excluded for brevity
> >
> >     // Does not work correctly
> >     mapping.JoinedSubClass<Manager>("BusinessId")
> >                 .HasMany(x => x.ManagedCustomers)
> >                 .KeyColumnNames.Add("PrimaryManagerFk")
> >                 .Inverse();
> >   }
> >
> > }
> >
> > The automapping gets the forward mapping right (i.e.,
> > mapping.JoinedSubClass<customer>("BusinessId").References<Manager>(x
> > => x.PrimaryManager)), but not the reverse, always using the wrong key
> > column.
> >
> > Thanks for helping.
> >
> > On Aug 11, 10:31 am, James Gregory <[email protected]> wrote:
> >
> > > Sorry, automapping or ClassMap's?
> >
> > > On Tue, Aug 11, 2009 at 3:11 PM, Chris Fazeli <[email protected]>
> wrote:
> >
> > > > Is the only solution here to use a manually created an HBM file for
> my
> > > > Business entity and its joined subclasses?
> >
> > > > Has no one else seen this problem?
> >
> > > > On Aug 5, 2:25 pm, Chris Fazeli <[email protected]> wrote:
> > > > > Hi again,
> >
> > > > > Can anyone give this a second look and give me even a guess? I'd
> > > > > appreciate it.
> >
> > > > > Thanks,
> > > > > -Chris
> >
> > > > > On Aug 3, 12:27 pm,ChrisFazeli<[email protected]> wrote:
> >
> > > > > > Hi,
> >
> > > > > > I posted about this in another post, but thought it might have
> gotten
> > > > > > buried under the wrong "Subject":
> > > >
> http://groups.google.com/group/fluent-nhibernate/browse_thread/thread...
> >
> > > > > > I have two tables that have two separate references to each
> other:
> > > > > > 1-to-many: 1 Manager to Many Customers (as PrimaryManagers)
> > > > > > many-to-many: Many Managers to Many Customers (as
> SecondaryManagers)
> >
> > > > > > Both of my domain model entities (Manager and Customer) inherit
> from
> > > > > > the same base Business class (joined subclasses).
> >
> > > > > > While I can get the many-to-many to map correctly using an
> automapping
> > > > > > override on the Business class, I cannot get the 1-to-many to map
> > > > > > correctly:
> >
> > > > > > // Does not work correctly
> > > > > > mapping.JoinedSubClass<Manager>("BusinessId")
> > > > > >        .HasMany(x => x.ManagedCustomers)
> > > > > >        .KeyColumnNames.Clear()
> > > > > >        .KeyColumnNames.Add("PrimaryManagerFk")
> > > > > >        .Inverse();
> >
> > > > > > // Works in this direction
> > > > > > mapping.JoinedSubClass<Customer>("BusinessId")
> > > > > >        .References<Manager>(x => x.PrimaryManager);
> >
> > > > > > Here's the output I get:
> >
> > > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > > > > > access="">
> > > > > >   <class name="Project.Business, Project, Version=1.0.0.0,
> > > > > > Culture=neutral, PublicKeyToken=null" table="Businesses"
> > > > > > xmlns="urn:nhibernate-mapping-2.2">
> > > > > >     ...
> > > > > >     <joined-subclass name="Project.Manager, Project,
> Version=1.0.0.0,
> > > > > > Culture=neutral, PublicKeyToken=null" table="Managers">
> > > > > >       <key column="BusinessId" />
> > > > > >      ...
> > > > > >       <bag name="Customers" inverse="true"
> > > > > > table="ManagersToCustomers">
> > > > > >         <key column="ManagerFk" />
> > > > > >         <many-to-many column="CustomerFk"
> class="Project.Customer,
> > > > > > Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
> />
> > > > > >       </bag>
> >
> > > > > > <!-- INCORRECT MAPPING STARTS -->
> >
> > > > > >       <bag name="ManagedCustomers" inverse="true">
> > > > > >         <key column="ManagerFk" />
> > > > > >         <one-to-many class="Project.Customer, Project,
> > > > > > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
> > > > > >       </bag>
> >
> > > > > > <!-- INCORRECT MAPPING STOPS -->
> >
> > > > > >     </joined-subclass>
> > > > > >     <joined-subclass name="Project.Customer, Project,
> Version=1.0.0.0,
> > > > > > Culture=neutral, PublicKeyToken=null" table="Customers">
> > > > > >       <key column="BusinessId" />
> > > > > >       ...
> > > > > >       <bag name="SecondaryManagers" table="ManagersToCustomers">
> > > > > >         <key column="CustomerFk" />
> > > > > >         <many-to-many column="ManagerFk" class="Project.Manager,
> > > > > > Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
> />
> > > > > >       </bag>
> > > > > >       <many-to-one name="PrimaryManager"
> column="PrimaryManagerFk" />
> > > > > >       ...
> > > > > >     </joined-subclass>
> > > > > >   </class>
> > > > > > </hibernate-mapping>
> >
> > > > > > What am I doing wrong? I've tried every tutorial and example, but
> > > > > > can't get the KeyColumnName to be correct.
> > > > > > -Chris
> >
>

--~--~---------~--~----~------------~-------~--~----~
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