The only way I can think of mapping that would be using a ManyToMany between the two of them (even though you're only ever going to get a single row back), and then projecting that backing field with a public property that just does something like a return backingCollectionField.First();
I don't know if there's a better way to do it. May jump onto: http://groups.google.com/group/nhusers and ask them (using NH xml mappings of course). If they can give you better xml to do it, we can probably show you how to map it in FNH. On Mon, Jan 25, 2010 at 11:12 AM, Boz <[email protected]> wrote: > I'm using a legacy database schema which cannot be changed (although > it can be added to, keys, columns etc). > > I have two tables that have no direct relationships between them. > There is then a third table, a link table, which simply references the > two tables with foreign keys. A record in this third table is meant > to be unique (although it isn't enforced with a key yet!) and it > indicates that a row in Table1 is related to only 1 row in Table2 and > vice-versa. > > Questions: > What classes should I have? > It seems like I ought to have just two classes that each have a single > reference to each other. > > How do I go about mapping this? > I can't use HasOne because that requires that the keys in each table > are unique, and besides I have the link table in the way. > > I could create 3 classes, one for each table, but I can't seem to > avoid implementing one-to-many relationships (which I couldn't get to > work either). > > I intend to add a composite key to the link table to enforce the > unique relationship, in case that assists with the mapping? > > Simplified schema, if it helps: > > Table1 (Table1_Id (pk), Name) > Table2 (Table2_Id (pk), Name) > Table3 (Table1_Id (fk), Table2_Id (fk)) > > Thanks in advance > > Boz > > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<fluent-nhibernate%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/fluent-nhibernate?hl=en. > > -- - Hudson http://www.bestguesstheory.com http://twitter.com/HudsonAkridge -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
