Foreign Key to a table with 2 columns primary key (CompositeId)

63 views
Skip to first unread message

Adam Fridental

unread,
Feb 11, 2012, 10:31:53 AM2/11/12
to Fluent NHibernate
I've defined the primary key (of 'EntityWith2ColsPK') as following:

CompositeId()
.KeyProperty(x => x.Id)
.KeyProperty(x => x.Type);

For the other entity, I've tried the following:

References(x => x.EntityWith2ColsPK);

And failed with:

Foreign key (Fk_MyEntity_EntityWith2ColsPK:MyEntities
[Fk_EntityWith2ColsPK])) must have same number of columns as the
referenced primary key (EntityWith2ColsPKs [Id, Type])

How can I reference EntityWith2ColsPK from another entity?

I've tried this:

HasMany<EntityWith2ColsPK>(x =>
x.EntityWith2ColsPK).KeyColumns.Add("Id", "Type").Cascade.All();

Which failed with:

Custom type does not implement UserCollectionType: Category

But anyway I don't want a 1 to many relation, I want a 1 to 1
relation. Still, I can't make either of them work.

Also, I've tried:

HasOne<EntityWith2ColsPK>(x => x.EntityWith2ColsPK).PropertyRef(x
=> x.Id).PropertyRef(x => x.Type);

Which fails with:

NHibernate.MappingException : property not found: Language on
entity AFR.Domain.Entities.Category

What can I do for this to really work?
Reply all
Reply to author
Forward
0 new messages