views:

70

answers:

1

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 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();
        }
    }

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

+6  A: 

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

Suggested read: http://wiki.fluentnhibernate.org/Getting_started

Diego Mijelshon
as in References(x => typeof(Person)).Column("PersonId").Not.Nullable()?
Shane
ok being thick got it, References(x => x.Person)
Shane
That's correct.
Diego Mijelshon