So everything is working well with the basic discriminator mapping. I can interact directly with entities A and B without any problems.
public class BaseType {}
public class EntityA : BaseType {}
public class EntityB : BaseType {}
This maps without drama in the BaseType mapping as
DiscriminateSubClassesOnColumn<string>("Type")
.SubClass<BaseType>("A", m => { })
.SubClass<BaseType>("B", m => { });
The problem occurs when: in an aggregate we want to map collections to each subclass
Using mapping like below
public class AggregateMap: BaseMap<Aggregate>
{
public AggregateMap()
{
HasMany<EntityA>(x => x.ACollection).AsSet().Cascade.All();
HasMany<EntityB>(x => x.BCollection).AsSet().Cascade.All();
}
}
These obviously arent full mappings but are the minimum amount to descibe what I am attempting. Items added to ACollection and BCollection are persisted correctly through the cascading when Aggregate is saved. However, when aggregate is retrieved there is confusion on the type discrimination.
I have run through so many different possible solutions I no longer know what didn't work. I feel that I shouldn't have to provide a where clause on the collections but things just aren't working for me.
Any clues would be appreciated.
You mapping looks odd, in particular I think it should look more like this
DiscriminateSubClassesOnColumn<string>("Type")
.SubClass<EntityA>("A", m => { })
.SubClass<EntityB>("B", m => { });
Having said that it seems that method is depreciated and you should instead define the following (taken from Automapping Subclasses:
public class ParentMap : ClassMap<Parent>
{
public ParentMap()
{
Id(x => x.Id);
Map(x => x.Name);
DiscriminateSubClassesOnColumn("type");
}
}
public class ChildMap : SubclassMap<Child>
{
public ChildMap()
{
Map(x => x.AnotherProperty);
}
}
Not sure this will fix it though, I am yet to encounter your scenario.
Edit: The issue is also raised here, sounding more like a bug to me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With