Reputation: 5320
I have a class that has an IList
of an enum type. Something like this :
public class Enitity
{
public IList<Usages> Usages{get;set;} //Usages is an enum type
}
To define this relation I have implemented IHasManyConvention
and IHasManyConventionAcceptance
like this :
public class HasManyEnumTypeConvention:IHasManyConvention,IHasManyConventionAcceptance
{
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Element.Type(instance.ChildType);
}
}
public void Accept(IAcceptanceCriteria<IOneToManyCollectionInspector> criteria)
{
criteria.Expect(instance => instance.ChildType != null && instance.ChildType.IsEnum);
}
When I try to build a Configuration object using this convention I get an exception as follow :
The element 'bag' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'one-to-many' in namespace 'urn:nhibernate-mapping-2.2'
That I suspect that FluentNhibernate
is adding both one-to-many
and element
elements to a bag.
Obviously I am doing something wrong but I couldn't find any example that uses automapping
to do the trick.
Please tell me how I can define a bag as an Element
using FluentNhibernate Automapping
?
Upvotes: 0
Views: 218
Reputation: 5320
Okay I figured it out :)
You should use an IAutomappingOverride
implementation to define a bag as an element
instead of one-to-many
. Here's how I did it :
public class EntityOverride:IAutoMappingOverride<Entity>
{
public void Override(AutoMapping<RealEstateFile> mapping)
{
mapping.HasMany(x => x.Usage).Element("Usages").AsBag();
}
}
Upvotes: 1