NHibernate Override<> for many-to-any
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...) 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
2 Posted by csizo on 09 Mar, 2010 01:26 PM
For shorting the question I'd like to know how to map with fluent nhibernate this domain:
Container -> Have many base item (abstract or interface) (IList<BaseItem> or IList<IBaseItem>)
Base Item -> (defines base properties to be persisted) and Have a Container Reference
ConcreteItem1 -> Derived from / or implements base item and Have other specific persisted properties
ConcreteItem2 -> Derived from /or implements base item and Have other specific properties ConcreteitemN (there can be N times implementations)
From the Container side I'm only interested in the IList<BaseItem> (or IList<IBaseItem>) properties and methods...
It would be used for a kind of AddOn handling,
1.)
where Container have some specific centralized logic regarding the AddOn installing, uninstalling, etc.
2.)
Generally the AddOn specifies the concrete implementation logic and and hides the details and "internal" properties for the Container.
Please guide me to resolve this problem.
Thanks
3 Posted by Kevin Fairclough on 01 Feb, 2011 11:21 AM
I would also like to know how to this with an override