NHibernate "property mapping has wrong number of columns"

0

I´m trying to get work the NHibernate mappings bellow but I have a the following error message:

NHibernate.MappingException HResult=0x80131500 Message=property mapping has wrong number of columns: CAF.Properties type: component[Codigo,Armazem,CAA_Armazem] Source=NHibernate
StackTrace: at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) in R:\github\nhibernate-core\src\NHibernate\Mapping\PersistentClass.cs:line 963 at NHibernate.Mapping.RootClass.Validate(IMapping mapping) in R:\github\nhibernate-core\src\NHibernate\Mapping\RootClass.cs:line 370 at NHibernate.Cfg.Configuration.ValidateEntities() in R:\github\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1042 at NHibernate.Cfg.Configuration.Validate() in R:\github\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 970 at NHibernate.Cfg.Configuration.BuildSessionFactory() in R:\github\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1268

If I remove the property-ref attribute from many-to-one element, the mapping compiles but the key field used to join is not correct (Entity2.Id instead of Entity2.Ref).

NHibernate 5.1.3, .Net Core 2.1

  <class name="Entity, Web" entity-name="Entity1" table="Table1">
    <id type="int" name="Id">
      <column name="Id"/>
      <generator class="native"/>
    </id>

    <dynamic-component name="CustomProperties">

      <property name="Ref" type="string" />
      <property name="Entity2Ref" type="string" />

      <many-to-one name="Entity2Join" 
        column="Entity2Ref" 
        entity-name="Entity2" 
        property-ref="CustomProperties.Ref" 
        insert="false" 
        update="false" 
        foreign-key="none" 
        fetch="join">
      </many-to-one>

    </dynamic-component>

  </class>

  <class name="Entity, Web" entity-name="Entity2" table="Table2">

    <id type="int" name="Id">
      <column name="Id"/>
      <generator class="native"/>
    </id>

    <dynamic-component name="CustomProperties">
      <property name="Ref" type="string" unique="true" />
      <property name="Property1" type="string" />
      <property name="Property2" type="string" />
      <property name="Property3" type="string" />
    </dynamic-component>

  </class>

public class Entity : DynamicObject
    {
        public virtual int Id { get; set; }
        private IDictionary _properties = null;

        public virtual IDictionary Properties
        {
            get
            {
                if (_properties == null)
                {
                    _properties = new Hashtable();
                }


                return _properties;
            }
            set
            {
                _properties = value;
            }
        }

        public override bool TryGetMember(
            GetMemberBinder binder, out object result)
        {
            string name = binder.Name;
            result = null;

            if (!Properties.Contains(name))
            {
                result = "";
                return true;
            }

            result = Properties[name];

            return true;
        }

        public override bool TrySetMember(
            SetMemberBinder binder, object value)
        {
            Properties[binder.Name] = value;

            return true;
        }

    }
nhibernate

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0