NHibernate“属性映射的列数错误”

时间:2018-08-15 00:48:39

标签: nhibernate

我正在尝试下面的NHibernate映射,但是出现以下错误消息:

  

NHibernate.MappingException HResult = 0x80131500消息=属性   映射的列数错误:CAF.Properties类型:   组件[Codigo,Armazem,CAA_Armazem]来源= NHibernate
  StackTrace:位于NHibernate.Mapping.PersistentClass.Validate(IMapping   映射)中   R:\ github \ nhibernate-core \ src \ NHibernate \ Mapping \ PersistentClass.cs:line   963在NHibernate.Mapping.RootClass.Validate(IMapping映射)中   R:\ github \ nhibernate-core \ src \ NHibernate \ Mapping \ RootClass.cs:第370行   在NHibernate.Cfg.Configuration.ValidateEntities()中   R:\ github \ nhibernate-core \ src \ NHibernate \ Cfg \ Configuration.cs:line   1042在NHibernate.Cfg.Configuration.Validate()中   R:\ github \ nhibernate-core \ src \ NHibernate \ Cfg \ Configuration.cs:line 970   在NHibernate.Cfg.Configuration.BuildSessionFactory()中   R:\ github \ nhibernate-core \ src \ NHibernate \ Cfg \ Configuration.cs:line   1268

如果我从property-ref元素中删除了many-to-one属性,则映射会编译,但是用于联接的键字段不正确(Entity2.Id而不是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;
        }

    }

0 个答案:

没有答案