English 中文(简体)
利用Fluent NHibernate绘图中的Join和部件,扔下“不可能找到财产例外的接收器”
原标题:Using a Join and Component together in Fluent NHibernate Mapping throws "Could not find a getter for property exception"

利用Fluent NHibernate绘图中的Join和部件扔下“不可能找到财产例外的通道”。 这是我的C#代码。

using FluentNHibernate.Mapping;

namespace FnhTest {
    public class CustomerMap : ClassMap<Customer> {
        public CustomerMap() {
            Id(x => x.Id).GeneratedBy.Identity();
            Map(x => x.Name);

            Join("BillingInfo", m =>
                               {
                                   m.KeyColumn("CustomerId");
                                   m.Component(x => x.BillingInfo, c =>
                                                                   {
                                                                       c.Map(y => y.AccountNumber);
                                                                       c.Map(y => y.Address);
                                                                   });
                               });
        }
    }

    public class BillingInfo {
        public virtual string AccountNumber { get; set; }
        public virtual string Address { get; set; }
    }

    public class Customer {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }

        public virtual BillingInfo BillingInfo { get; set; }
    }
}

这是我的数据库结构 =>

Customers:
  Id (int)
  Name (varchar 50)
BillingInfo:
  Id (int)
  AccountNumber (varchar 50)
  Address (varchar 50)
  CustomerId (int) (Foriegn Key to the Customers Id)

液态的NHibernate为这一装置绘制了正确的地图,但出于某种原因,它造成了错误。 下面是地图和错误。

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" name="FnhTest.Customer, FnhTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Customer`">
    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Id" />
      <generator class="identity" />
    </id>
    <property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Name" />
    </property>
    <join table="BillingInfo">
      <key>
        <column name="CustomerId" />
      </key>
      <component name="BillingInfo" insert="true" update="true" optimistic-lock="true">
        <property name="AccountNumber" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="AccountNumber" />
        </property>
        <property name="Address" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="Address" />
        </property>
      </component>
    </join>
  </class>
</hibernate-mapping>

TestCase  M:FnhTest.Program.Main(System.String[]) 
failed: 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.

    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.PropertyNotFoundException: Could not find a getter for property  AccountNumber  in class  FnhTest.Customer 
    at NHibernate.Properties.BasicPropertyAccessor.GetGetter(Type type, String propertyName)
    at NHibernate.Tuple.Component.PocoComponentTuplizer.BuildGetter(Component component, Property prop)
    at NHibernate.Tuple.Component.AbstractComponentTuplizer..ctor(Component component)
    at NHibernate.Tuple.Component.PocoComponentTuplizer..ctor(Component component)
    at NHibernate.Tuple.Component.ComponentEntityModeToTuplizerMapping..ctor(Component component)
    at NHibernate.Tuple.Component.ComponentMetamodel..ctor(Component component)
    at NHibernate.Mapping.Component.BuildType()
    at NHibernate.Mapping.Component.get_Type()
    at NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping)
    at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping)
    at NHibernate.Mapping.RootClass.Validate(IMapping mapping)
    at NHibernate.Cfg.Configuration.Validate()
    at NHibernate.Cfg.Configuration.BuildSessionFactory()
    d:BuildsFluentNHsrcFluentNHibernateCfgFluentConfiguration.cs(93,0): at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
       --- End of inner exception stack trace ---
    d:BuildsFluentNHsrcFluentNHibernateCfgFluentConfiguration.cs(100,0): at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
    D:
epositoriescoreplaygroundminhajuddinFnhTestFnhTestProgram.cs(8,0): at FnhTest.Program.Main(String[] args)

      * Database was not configured through Database method.


0 passed, 1 failed, 0 skipped, took 6.46 seconds (Ad hoc).

我在网上进行了搜索,但找不到任何帮助。

EDIT: Well, I didn t find a way to do this in Fluent NHibernate, I am using whatever Torkel has posted as an answer. But, that was not my intention. Anyway.

最佳回答

BillingInfo看我不是一个组成部分,而是一个实体。

如果你把“FillingInfo”描绘成一个实体,你可以把客户描绘成一个协会。

<many-to-one name="BillingInfo" property-ref="CustomerId" cascade="none"/>

不动产是进口的,因为你不想加入《账单》,而是寄给客户,但这要求你在《账单目录》中增加客户财产。

问题回答

如果这是一条umb子,但你不需要一名伊德成员参加比尔·Info?





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签