Reputation: 1372
I am working with legacy database and trying to create map with certain tables.
Theres profile for user, profile has reference to contact channel. However, in database key for user is composite key. This is somewhat ok, but theres some magic strings in database which should be nice if they can be converted to more typed versions.
In profile map:
CompositeId()
.KeyProperty(x => x.ServiceId, "SERVICE_ID")
.KeyProperty(x => x.Direction, "DIRECTION").CustomType<DirectionConverter>()
.KeyReference(x => x.Channel, new string[] { "CHANNEL_ID", "CONTACT_TYPE", "DIRECTION", "SERVICE_ID" })
.KeyProperty(x => x.ContactType, "CONTACT_TYPE")
.KeyReference(x => x.Agent, "AGENT_ID");
Problem is line:
.KeyReference(x => x.Channel, new string[] { "CHANNEL_ID", "CONTACT_TYPE", "DIRECTION", "SERVICE_ID" })
(So channel has composite key also ...)
In that reference i don't know how to tell fluent nhibernate to use converter for "DIRECTION" column handling. In practise this can be seen as that converter will receive null value on NullSafeSet.
Is there existing solution for this or is only option not to use converters for this kind of columns?
Upvotes: 1
Views: 761
Reputation: 1372
Solved.
Mapping was incorrect.
CompositeId()
.KeyProperty(x => x.ServiceId, "SERVICE_ID")
.KeyProperty(x => x.Direction, "DIRECTION").CustomType<DirectionConverter>()
.KeyReference(x => x.Channel, new string[] { "CHANNEL_ID", "CONTACT_TYPE", "DIRECTION", "SERVICE_ID" })
.KeyProperty(x => x.ContactType, "CONTACT_TYPE")
.KeyReference(x => x.Agent, "AGENT_ID");
Correct version:
CompositeId()
.KeyReference(x => x.Channel, new string[] { "CHANNEL_ID", "CONTACT_TYPE", "DIRECTION", "SERVICE_ID" })
.KeyReference(x => x.Agent, "AGENT_ID");
Now i can use ChannelId, ContactType, Direction, ServiceId, AgentId as composite key in this class. Incorrect converter was symptom of this problem but error messages were very misleading one.
Upvotes: 2