Hi,

I have a Customer entity and a Manager entity. Both are joined
subclasses of a Business entity.
One customer can be managed by many managers:
    public virtual IList<Manager> Managers { get; set; }
One manager can manage many customers:
    public virtual IList<Customer> Customers { get; set; }

It is my understanding that automapping doesn't pick this up. So I map
manually with overrides:
public class CustomerMap : IAutoMappingOverride<Customer>
{
    public void Override(AutoMap<Customer> mapping)
    {
        mapping.HasManyToMany<Manager>(x => x.Managers)
            .AsBag()
            .WithTableName("ManagersCustomers")
            .WithParentKeyColumn("CustomerFk")
            .WithChildKeyColumn("ManagerFk");
    }
}

public class ManagerMap : IAutoMappingOverride<Manager>
{
    public void Override(AutoMap<Manager> mapping)
    {
        mapping.HasManyToMany<Customer>(x => x.Customers)
            .AsBag()
            .WithTableName("ManagersCustomers")
            .WithParentKeyColumn("ManagerFk")
            .WithChildKeyColumn("CustomerFk")
            .Inverse();
    }
}

These overrides are executed, but in
FluentNhibernate.AutoMap.AutoPersistenceModel, the MergeMap method
calls GetTypeToMap, and this does a check to see if the type's
basetype should be passed back. I get a failure here. Using S#arp
Arch's CanConfirmDatabaseMatchesMappings test, I see the exeption:

  ----> System.ArgumentException : Object of type
'FluentNHibernate.AutoMap.AutoMap`1[Project.Customer]' cannot be
converted to type 'FluentNHibernate.AutoMap.AutoMap`1
[Project.Business]'.
TearDown : System.Reflection.TargetInvocationException : Exception has
been thrown by the target of an invocation.
  ----> System.Collections.Generic.KeyNotFoundException : The given
key was not present in the dictionary.


Can anyone help with this? I'm not quite sure what to do about it!

For completeness, there's also a one-to-many mapping between Managers
and Customers, where the customer has the notion of a PrimaryManager,
and an inverse relationship exists in the Manager as a list of
ManagedCustomers. I figure this gets picked up by the automapper.

Thanks,
- 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