Hi, One way for doing this is to use the documentid as a primary key(or apply a unique constraint) in the CompanyToDocument table so that it shares a one-to-one relationship with Document table.
I think the OR Map too is clear in this case. Regards Surya On Thu, Mar 15, 2012 at 2:34 AM, jksoft <[email protected]> wrote: > First off, I am relatively new to NHibernate and so far finding good > documentation has been a trial. > > I am in the processing of using NH to connect to a legacy application > which also includes some new tables we are adding for this project. The > database makes extensive use of join tables to link two entities together. > An example would be > > Company --> CompanyToDocument <-- Document > CompanyToDocument > - companyId > - documentId > > While this is a traditional way of doing Many to Many relationships, it > really is a One to Many as each *Document *can only be associated with > one *Company*. > > I have been racking my brain trying to figure out how to model this in the > application and use NH to map appropriately. I really want my *Document > *class > to either have a "*companyId*" property or a Company property, not a > collection of Companies which is the natural mapping for a Many to Many. > > One idea I came up with was to put both a *Company *and a *Companies *property > on my *Document *class so the NH Many to Many association would work. > The problem with this is I still can't do a query using my *companyId > *property > since NH doesn't know anything about it. One thought I had is to use a > Join association to map the *companyId *property. I suppose another > thought would be to tweak the query to join back to the Join table. > > I wanted to seek out some advice as the pieces just don't seem to be > fitting in place which makes me think I must be doing something wrong here. > > I am open to any and all ideas here as I am stumped on this. > > Thanks for any advice, > > J > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/nhusers/-/x8eTnz-LzOUJ. > 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/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en.
