I am sure someone has to have done this before - looking at the previous queries it possibly cannot be done with Fluent - but here goes:
I have the following mappings
As you can probably spot - this is not going to work because the keys on the child table do not match the parent table and so the error will be that the number of fields on the foreign key contract don't match. However, I cannot change the underlying tables (and the relationship is a valid one). Is there a way around this in fluent nhibernate so I can somehow ignore the expected join on both composite fields and only join on the one which matches (i.e field_one?) Hibernate expects that field one and field two are present on both mappings.
public ParentMap()
{
Table("dbo.SOMEPARENT");
OptimisticLock.None();
LazyLoad();
CompositeId()
.KeyReference(x => x.FieldOne, x => x.Access.CamelCaseField(Prefix.Underscore), "field_one")
.KeyReference(x => x.FieldTwo, x => x.Access.CamelCaseField(Prefix.Underscore), "field_two");
HasMany(x => x.ChildData)
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.AllDeleteOrphan()
.KeyColumns.Add("field_one")
.NotFound.Ignore();
}
public ChildDataMap()
{
Table("dbo.SOMECHILD");
OptimisticLock.None();
LazyLoad();
CompositeId()
.KeyProperty(x => x.FieldOne, x => x.Access.CamelCaseField(Prefix.Underscore).ColumnName("field_one"))
.KeyProperty(x => x.FieldTwo, x => x.Access.CamelCaseField(Prefix.Underscore).ColumnName("field_two"))
.KeyProperty(x => x.FieldThree, x => x.Access.CamelCaseField(Prefix.Underscore).ColumnName("field_three"))
.KeyProperty(x => x.FieldFour, x => x.Access.CamelCaseField(Prefix.Underscore).ColumnName("field_four"));
Map(x=>x.DontExecTrigger).Column("dont_exec_trigger").Access.CamelCaseField(Prefix.Underscore);
Map(x=>x.DateField).Column("date_field").Access.CamelCaseField(Prefix.Underscore);
Map(x=>x.DataField).Column("data_field").Access.CamelCaseField(Prefix.Underscore);
References(x => x.Parent)
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.All()
.Fetch.Select()
.Columns("field_one")
.NotFound.Ignore()
.Not.LazyLoad();
}