Hello all,
(this is cross-posted to the list and StackOverflow - http://stackoverflow.com/questions/6213658/ - is that OK? Shout if it's not and I won't do it again!)
I have these tables in my SQL Server database. MemberCv is a legacy table that we can't modify, so we're using an NHibernate join mapping to map the extra columns we need for a new feature:
MemberCv (
MemberId varchar -- part of composite key,
PublicationCode int -- part of composite key,
PictureFileName varchar -- UNIQUE KEY constraint UK_PictureFileName
)
PhotoSTatus (
FileName varchar -- primary key,
IsHidden bit,
Sequence int
)
and so the resulting C# class will look like:
public class MemberCv {
public Member Member { get; set; }
public Publication Publication { get; set; }
public string FileName { get; set; }
public int IsHidden { get; set; }
public int Sequence { get; set; }
}
The problem is, NHibernate (using Fluent NH) is trying to map it using the primary (composite) key that's defined on the MemberCv table. Yes, I know NHibernate hates primary keys. No, I can't introduce an artificial key and turn the existing one into a unique constraint.
In the MemberCv override map, we have tried:
map.Join("PhotoStatus", join
.KeyColumn("FileName")
.References(cv => cv.PictureFileName)
.UniqueKey("UK_PictureRef");
which results in:
NHibernate.FKUnmatchingColumnsException : Foreign key (FK3F10D2B7EA4868D8:MyDatabase.dbo.PhotoStatus [FileName])) must have same number of columns as the referenced primary key (MemberCv[Member, Publication])
We've even tried using computed columns in the PhotoStatus table (Filename is based on MemberId and PublicationCode, so it's possible to compute the elements of the associated composite key) and then using implicit joining, which results in:
NHibernate.FKUnmatchingColumnsException : Foreign key (FK3F10D2B7F670FD07:MyDatabase.dbo.PhotoStatus [MemberCv_id])) must have same number of columns as the referenced primary key (MemberCv[Member, Publication])
Any ideas? This is one of those scenarios that should be quite easy but we just can't find the right configuration for it...
I'll do some digging.In the meantime, do you need to insert into this table? (please say no). If not, you could use a view to get around the problem. I'll try find a proper solution.
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/ZnlGOFRTeHFDN29K.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.