views:

50

answers:

0

I have a question for a specific many-to-any mapping problem:

I'd like to have a fluent mapping for this simplified domain (non relevant properties removed)

public interface IModule
{
  Container Container { get; }
}

//This is mapped to [dbo].Container table in the database 
public class Container: Entity
{
  // ...
  // I need to map this IList
  public virtual IList<IModule> Modules { get; protected set; }
  // ...
}

// This is mapped to [dbo].Module1 table in the database
public class Module1: Entity, IModule
{
  // ...
  public virtual Container Container { get; protected set; } //Module1 has Container reference (mapped)
  // ...
}

// this is mapped to [dbo].Module2 table in the database
public class Module2: Entity, IModule
{
  // ...
  public virtual Container Container { get; protected set; } //Module2 has Container reference (mapped)
  // ...
}

According to Ayende blog entry (http://ayende.com/Blog/archive/2009/04/22/nhibernate-mapping-ltmany-to-anygt.aspx) I have to provide this (or similar) mapping:

<set name="Modules" table="ContainerModules" cascade="all">
 <key column="ContainerId"/>
 <many-to-any id-type="System.Int64"
   meta-type="System.String">
  <meta-value value="Module1"
   class="Module1"/>
  <meta-value value="Module2"
   class="Module2"/>
  <column name="ModuleType" 
   not-null="true"/>
  <column name="ModuleId"
   not-null="true"/>
 </many-to-any>
</set>

I have this (as again simplified) persistenceModel declaration...

var persistanceModel = AutoMap
.AssemblyOf<Domain.Placeholder>()
.Conventions.AddFromAssemblyOf<ClassConvention>()
.UseOverridesFromAssemblyOf<AutoMappingOverridePlaceholder>()
.Setup(s =>
{
    s.SubclassStrategy = type => SubclassStrategy.JoinedSubclass;
    s.IsComponentType = type => type.IsMarkedWith<ComponentAttribute>();
})
.IgnoreBase<Entity>()
.Where(type => !type.IsAbstract && typeof(Entity).IsAssignableFrom(type));

So how can this be achieved with fluent override or automap convention?

Thanks