Hi all
NHibernate version: 1.2.0RC1
Database: MSSQL2000
I have searched for solutions to this, but haven't found any, even though it doesn't seem too exotic:
I'm having two tables, for example like:
Code:
Persons(Id,Name,Address,ZipCode,etc.)
ZipCodes(Id,ZipCode,Town,etc.)
ZipCodes is related one-to-many to Persons, on the column named ZipCode (in both tables), but both tables has a surrogate key "Id" that is the primary key.
How do I map this in NHibernate (I'm using NHibernate.Mapping.Attributes, but since I can insert raw xml, a .hbm mapping file example will also do)?
Please don't ask me to change the database-schema, since I can't (the above example isn't the actual db-schema, but an example that points out the problem).
I have tried mappings along the lines of:
Code:
[Bag(1)]
[Key(2, Column = "ZipCode")]
[OneToMany(3, ClassType = typeof(Person))]
public virtual IList<Person> Persons { ...
But that will map Person.ZipCode to ZipCode.Id (the primary key of the parent), and I can't figure out how to specify the column in the parent table (ZipCodes).
Any help is highly appreciated.
Best regards
/Kasper
[/code]