I've setup my automappings so the default Subclass Strategy is
Subclass:
autoMappings.Setup( s => s.SubclassStrategy = t =>
SubclassStrategy.Subclass );
I've included the parent of the class Hierarchy with:
autoMappings.IncludeBase<Parent>();
I have also defined an IAutoMappingOverride for the Parent:
public class ParentOverrideMap : IAutoMappingOverride<Parent>
{
public void
Override( FluentNHibernate.Automapping.AutoMapping<Parent> mapping )
{
mapping.DiscriminateSubClassesOnColumn( "Type" );
mapping.SubClass<ChildA>( "ChildA" );
}
}
From what I've read on the Wiki on in various Google searches it seems
like that should work, but when I test it by using the SchemaExport
tool, it builds the table with the discriminator column name as
"discriminator" instead of "Type". So it seems my overrides aren't
working.
The documentation on the Wiki doesn't cover this, so I've mostly been
guessing, that's why I'm wondering if anyone could point me to an
article somewhere with a good example of using the table-per-class-
hierarchy strategy with automappings.
Thanks,
Kevin
Thanks,
Kevin
On Mar 22, 3:06 pm, kberridge <kevin.w.berri...@gmail.com> wrote:
> Last check, can anyone provide any direction for me on this?
>
> Thanks,
> Kevin
>
> On Mar 9, 6:37 pm, kberridge <kevin.w.berri...@gmail.com> wrote:
>
> > Hi,
> > I'm looking for an example of how to use a table-per-class-hierarchies
> > with Automapper.
>
> > I've setup my automappings so the default Subclass Strategy is
> > Subclass:
> > autoMappings.Setup( s => s.SubclassStrategy = t =>
> > SubclassStrategy.Subclass );
>
> > I've included the parent of the class Hierarchy with:
> > autoMappings.IncludeBase<Parent>();
>
> > I have also defined an IAutoMappingOverride for the Parent:
> > public class ParentOverrideMap : IAutoMappingOverride<Parent>
> > {
> > public void
> > Override( FluentNHibernate.Automapping.AutoMapping<Parent> mapping )
> > {
> > mapping.DiscriminateSubClassesOnColumn( "Type" );
> > mapping.SubClass<ChildA>( "ChildA" );
> > }
>
> > }
>
> > From what I've read on the Wiki on in various Google searches it seems
> > like that should work, but when I test it by using the SchemaExport
> > tool, it builds the table with thediscriminatorcolumn name as
DiscriminatorColumn = type => (type == typeof(MyClass)) ?
"IsHomeTeam" : "discriminator";
But I've been having no luck in determining a way to set
DiscriminatorColumn type and removed the classes altogether from
AutoMapping (btw, we should really make this easier, the ignoring from
automapper part).
Best of luck,
Felipe
On Apr 10, 1:14 pm, reach4thelasers <kev.m.mul...@googlemail.com>
wrote:
I posted a question here a few weeks ago looking for a way to see if
there was a convention I could use and how to use it but no responses
at all, and definitely not obviously documented. I do get the
inheritance behavior at least! Life in the open source lane ...
Cheers,
Berryl
Now, if I add something simple as:
if (((ClassMapping)mapping).Discriminator != null) {
discriminatorSet = true;
}
Then it works. And I can even change the discriminator using an
Override, but I've yet to find a way to create a Subclass Override. If
I can find one, then I'm gold.
Anyway, I'll do some further working on this and let you guys know of
any updates.
Cya,
Felipe
if (isDiscriminated && !discriminatorSet && mapping is ClassMapping)
{
if (((ClassMapping)mapping).Discriminator != null)
{
discriminatorSet = true;
}
else {
var discriminatorColumn =
expressions.DiscriminatorColumn(classType);
var discriminator = new DiscriminatorMapping {
ContainingEntityType = classType,
Type = new TypeReference(typeof(string))
};
discriminator.AddDefaultColumn(new
ColumnMapping { Name = discriminatorColumn });
((ClassMapping)mapping).Discriminator =
discriminator;
discriminatorSet = true;
}
}
Now is off to figure out a way to make an Override for Subclass OR
create a new Convention perhaps to set DiscriminatorValue for the
subclasses.