Hello,
recently I ran into a problem mapping the classes of a legacy database.
There are two tables, one of them with a composite uniquekey which is referenced from another table.
Example:
Person
------
Id (PK)
FirstName (UK)
LastName (UK)
Car
-----
Id (PK)
OwnerFirstName (FK)
OwnerLastName (FK)
Is it possible to create a mapping for this with fluent nhibernate?
My first attempt was:
Code:
internal class PersonMap: ClassMap<Person>
{
public PersonMap()
{
this.HasMany(x => x.E3FkFslFasaMetaList)
.KeyColumns.Add("FirstName").PropertyRef("FirstName")
.KeyColumns.Add("LastName").PropertyRef("LastName")
.Cascade.All().Inverse();
this.Id(x => x.Id).GeneratedBy.NaturalId;
this.Map(x => x.FirstName).Not.Nullable().UniqueKey("UK");;
this.Map(x => x.LastName).Not.Nullable().UniqueKey("UK");;
}
}
internal class CarMap: ClassMap<Car>
{
public CarMap()
{
this.Id(x => x.Id).GeneratedBy.NaturalId;
this.References(x => x.FkName).Columns("FirstName", "LastName");
}
}
This sadly isnt working because the mapping tries to reference to the primarykey of the Person.
How can I tell him to use the uniquekey for this relation?
Greetings tom