fluent-nhibernate
fluent-nhibernate copied to clipboard
FNH 1.3: Mapping to the ICompositeUserType broken
Yesterday I grab last available sources of FNH to make it possible to use it with NH 3.2.0.4GA. But after update to new version (1.3) I start getting the following error:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
- Database was not configured through Database method. ---> NHibernate.MappingException: property mapping has wrong number of columns: CashDepartment.Server.DomainModel.Enities.Service.Rate type: component[RateType,PaymentCondition,FixedAmountData,FixedCostOfArivalData,PercentageData] at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\PersistentClass.cs:line 954 at NHibernate.Mapping.RootClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\RootClass.cs:line 371 at NHibernate.Cfg.Configuration.ValidateEntities() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1030 at NHibernate.Cfg.Configuration.Validate() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 958 at NHibernate.Cfg.Configuration.BuildSessionFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1250 at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() --- End of inner exception stack trace --- at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
This happens then I map ICompositeUserType:
C# Map(m => m.Amount).CustomType<MoneyCompositeType>();
After call CustomType method, returned PropertyPart object contains correct number of columns, but then FNH visitor visit this property during NH mapping generation it Columns collection contains only one column named as Property.
May be this information will be useful: this property located in class that mapped as Component.
I think this is the bug. How can I fix it?
Any news? I must migrate to the NH mapping from code? Issue not closed... this is mistake!
I am getting this same exception while trying to map an ICompositeUserType - is this an issue with FNH or not?
its still buggy. Columns.Clear() doesn't help
Edit: Ok, first set the CustomType and than add the columns with an clear: this.Map(x => x.MapSize).Not.Nullable().CustomType<ObjectSizeUserType>().Columns.Clear().Columns.Add("MapWidth", "MapHeight");
Can someone provide full code sample on that?
I'm getting it on a Component map with no user types. I'll have to see if I can isolate it down.
Ok, When I use a component map like
Component(x => x.Volume, c =>
{
c.Map(o => o.Measure);
c.Map(o => o.UnitOfMeasure);
});
Where Measure and UnitOfMeasure are user types
and I'm applying this Component convention.
public class ComponentPropertyConvention :
IPropertyConvention,
IPropertyConventionAcceptance
{
public void Apply(IPropertyInstance instance)
{
var y = instance.EntityType.Name.ToPostgresName();
var z = instance.Property.Name.ToPostgresName();
var name = $"{y}_{z}";
instance.Column(name);
}
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(isThisPropertyAComponent);
}
bool isThisPropertyAComponent(IPropertyInspector prop)
{
var propertyType = prop.Property.PropertyType;
var propertyName = prop.Name;
var entityType = prop.EntityType;
//an entity
var isComponent = !entityType.Implements(typeof(Identifiable<>))
//not an egg primitive
&& !entityType.Implements(typeof(ValueObject<>))
//not a primitive
&& !entityType.IsPrimitive
//not a value type (int, long, decimal, etc)
&& !entityType.IsValueType;
//should be a class that is not identifiable
return isComponent;
}
}
I get the issue.