Simple Fluent NHibernate Mapping Problem
Posted
by
user500038
on Stack Overflow
See other posts from Stack Overflow
or by user500038
Published on 2011-03-03T15:14:50Z
Indexed on
2011/03/03
15:25 UTC
Read the original article
Hit count: 177
nhibernate
|fluent-nhibernate
I have the following tables I need to map:
+-------------------------+
| Person |
+-------------------------+
| PersonId |
| FullName |
+-------------------------+
+-------------------------+
| PersonAddress |
+-------------------------+
| PersonId |
| AddressId |
| IsDefault |
+-------------------------+
+-------------------------+
| Address |
+-------------------------+
| AddressId |
| State |
+-------------------------+
And the following classes:
public class Person
{
public virtual int Id { get; set; }
public virtual string FullName { get; set; }
}
public class PersonAddress
{
public virtual Person Person { get; set; }
public virtual Address Address { get; set; }
public virtual bool IsDefault { get; set; }
}
public class Address
{
public virtual int Id { get; set; }
public virtual string State { get; set; }
}
And finally the mappings:
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id, "PersonId");
}
}
public class PersonAddressMap : ClassMap<PersonAddress>
{
public PersonAddressMap()
{
CompositeId().KeyProperty(x => x.Person, "PersonID")
.KeyProperty(x => x.Address, "AddressID");
}
}
public class AddressMap: ClassMap<Address>
{
public AddressMap()
{
Id(x => x.Id, "AddressId");
}
}
Assume I cannot alter the tables. If I take the mapping class (PersonAddress) out of the equation, everything works fine. If I put it back in I get:
Could not determine type for: Person, Person, Version=1.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(PersonId)
What am I missing here? I'm sure this must be simple.
© Stack Overflow or respective owner