The legacy legacy database contains the following tables:
Teams ( TeamId INT PRIMARY KEY, Name VARCHAR(30) ) Players ( PlayerId INT PRIMARY KEY, Team VARCHAR(30) )
The foreign key in the players table refers to the name of the team, not to the team.
I tried to match the Team team to the players using the bag:
<bag name="Players"> <key column="Team" foreign-key="Name" /> <one-to-many class="DataTransfer.Player, DataTransfer" /> </bag>
But I get SqlException: Conversion error when converting varchar 'Arsenal' value to int data type
I was able to use the bag to map foreign keys in other areas, but in these cases the foreign key referred to the primary key of the parent table.
Edit: I am using NHibernate 2.0.1
source share