Fluent-NHibernate映射错误

Fluent-NHibernate映射错误,nhibernate,fluent-nhibernate,Nhibernate,Fluent Nhibernate,我使用Fluent时出现以下错误: 12:16:47879错误[7] 配置[(null)]-关联 从表地址引用一个 未映射的类:System.Int32 NHibernate.MappingException:一个 表地址的关联 指未映射的类: System.Int32 公共类地址{ 公共广播{ } 公共虚拟整数地址ID{ 得到; 设置 } 公共虚拟字符串地址行1{ 得到; 设置 } 公共虚拟字符串地址行2{ 得到; 设置 } 公共虚拟字符串地址行3{ 得到; 设置 } 公共虚拟字符串Build

我使用Fluent时出现以下错误:

12:16:47879错误[7] 配置[(null)]-关联 从表地址引用一个 未映射的类:System.Int32 NHibernate.MappingException:一个 表地址的关联 指未映射的类: System.Int32

公共类地址{
公共广播{
}
公共虚拟整数地址ID{
得到;
设置
}
公共虚拟字符串地址行1{
得到;
设置
}
公共虚拟字符串地址行2{
得到;
设置
}
公共虚拟字符串地址行3{
得到;
设置
}
公共虚拟字符串BuildingNumber{
得到;
设置
}
公共虚拟城市{
得到;
设置
}
公共虚拟字符串县{
得到;
设置
}
public virtual System.DateTime MovedIn{
得到;
设置
}
公共虚拟系统.DateTime MovedOut{
得到;
设置
}
公共虚拟int PersonId{
得到;
设置
}
公共虚拟字符串邮政编码{
得到;
设置
}
} 
公共类地址映射:类映射{
公共地址映射(){
表(“地址”);
懒散的负荷();
Id(x=>x.AddressId).GeneratedBy.HiLo(“1000”);
Map(x=>x.AddressLine1).Length(100).Not.Nullable();
Map(x=>x.AddressLine2).Length(100).Not.Nullable();
Map(x=>x.AddressLine3).Length(100).Not.Nullable();
Map(x=>x.BuildingNumber).Length(250).Not.Nullable();
Map(x=>x.City).Length(250).Not.Nullable();
Map(x=>x.County).Length(250).Not.Nullable();
Map(x=>x.MovedIn).Not.Nullable();
Map(x=>x.MovedOut).Not.Nullable();
引用(x=>x.PersonId).Column(“PersonId”).Not.null();
Map(x=>x.PostCode).Length(15).Not.Nullable();
}
}
[测试夹具]
公共类测试库
{
受保护的会话源会话源{get;set;}
受保护的ISession会话{get;private set;}
[设置]
公共void SetupContext()
{
var cfg=fluntly.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(
“数据源=本地主机;初始目录=ted;用户ID=sa;密码=xxxx;”);
SessionSource=新的SessionSource(cfg.BuildConfiguration()/**此处有错误**
.Properties,新的TestModel());
Session=SessionSource.CreateSession();
SessionSource.BuildSchema(会话);
}
[撕裂]
public void TearDownContext()
{
Session.Close();
Session.Dispose();
}
}

我的初始配置有一个错误,我已经检查过几次了,我真的不确定我到底做错了什么?有人能看到明显的东西吗?我可以确认此表的数据库中只有2个int。AddressId-非身份PK和PersonId非身份FK

您应该拥有Person类型的Person属性,而不是id

建议阅读:

如参考文献(x=>typeof(Person)).Column(“PersonId”)。Not.Nullable()?
 public class Address {
        public Address() {
        }
        public virtual int AddressId {
            get;
            set;
        }
        public virtual string AddressLine1 {
            get;
            set;
        }
        public virtual string AddressLine2 {
            get;
            set;
        }
        public virtual string AddressLine3 {
            get;
            set;
        }
        public virtual string BuildingNumber {
            get;
            set;
        }
        public virtual string City {
            get;
            set;
        }
        public virtual string County {
            get;
            set;
        }
        public virtual System.DateTime MovedIn {
            get;
            set;
        }
        public virtual System.DateTime MovedOut {
            get;
            set;
        }
        public virtual int PersonId {
            get;
            set;
        }
        public virtual string PostCode {
            get;
            set;
        }
    } 

 public class AddressMap : ClassMap<Address> {

        public AddressMap() {
   Table("Address");
   LazyLoad();
            Id(x => x.AddressId).GeneratedBy.HiLo("1000");
   Map(x => x.AddressLine1).Length(100).Not.Nullable();
   Map(x => x.AddressLine2).Length(100).Not.Nullable();
   Map(x => x.AddressLine3).Length(100).Not.Nullable();
   Map(x => x.BuildingNumber).Length(250).Not.Nullable();
   Map(x => x.City).Length(250).Not.Nullable();
   Map(x => x.County).Length(250).Not.Nullable();
   Map(x => x.MovedIn).Not.Nullable();
   Map(x => x.MovedOut).Not.Nullable();
   References(x => x.PersonId).Column("PersonId").Not.Nullable();
   Map(x => x.PostCode).Length(15).Not.Nullable();
        }
    }


[TestFixture]
    public class TestBase
    {
        protected SessionSource SessionSource { get; set; }
        protected ISession Session { get; private set; }

        [SetUp]
        public void SetupContext()
        {
            var cfg = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                    "Data Source=localhost;Initial Catalog=ted;User ID=sa;Password=xxxx;"));
            SessionSource = new SessionSource(cfg.BuildConfiguration()//**Error Here**
                                                 .Properties, new TestModel());
            Session = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);
        }
        [TearDown]
        public void TearDownContext()
        {
            Session.Close();
            Session.Dispose();
        }
    }