开发者

Fluent NHibernate Mapping Error

开发者 https://www.devze.com 2023-01-11 10:00 出处:网络
I am getting the following error using Fluent: 12:16:47,879 ERROR [7] Configuration [(null)]- An association

I am getting the following error using Fluent:

12:16:47,879 ERROR [ 7] Configuration [(null)]- An association from the table Address refers to an unmapped class: System.Int32 NHibernate.MappingException: An association from the table Address refers to an unmapped class: System.Int32

 public class Address {
        public Address() {
        }
        public virtual int AddressId {
            get;
            set;
        }
        public virtual string Ad开发者_StackOverflowdressLine1 {
            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();
        }
    }

I get an error on my initial configuration, I have been over it a few times and I am really unsure what exactly I am doing wrong? Can anyone see anything Obvious? I can confirm there is only 2 int's in the database for this table. AddressId - Non identity PK and PersonId non identity FK


You should have a Person property of type Person, not an id.

Suggested read: https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started

0

精彩评论

暂无评论...
验证码 换一张
取 消