Join is exclusively for when you have an entity that is composed of multiple tables, nothing else; it's not a true relationship. References and HasMany should be used for just about everything, and definitely anything that can be considered an entity in it's own right.
On Sun, Feb 21, 2010 at 12:19 AM, James Nguyen <[email protected]> wrote: > Well, discovered why my Reference() attempt was bombing at runtime-- > apparently if I don't specify a Fetch statement, it blows up w/ an > exception noting that no session was available. Now, I was under the > impression that Fetch defaulted to Join(), but until I explicitly > included it in my mapping, this didn't work. > > So that's great--I have things working as I wanted them (and for real > domain models--not this simplified address example). > > But what I guess is still troubling me is that I'm not sure I > understand when one is intended to use References()/HasMany() versus > when one is supposed to use Join(). Some guidance there would be > highly illuminating! > > TIA > > James > > On Feb 20, 12:32 pm, James Nguyen <[email protected]> wrote: > > I have a seemingly simple join that I can't seem to get working > > properly--more specifically, the join works, and my child object is > > properly assembled--but I get the wrong value. I'm sure this is a > > case of my not wholly grokking what's the appropriate mapping > > mechanism for different contexts. > > > > I'll use Addresses to illustrate. > > > > public class Address { > > //usual suspects > > State State; > > > > } > > > > public class State { > > [Id, Name, Shortname] > > > > } > > > > -- > > I've tried several different ways of mapping this, as I don't think I > > fully understand what distinguishes each. Component(), > > HasOne<State>(), ReferencesAny<State>() all ultimately ended up with > > runtime exceptions. I believe what I'm after is a simple Join(), but > > as I stated, I'm getting a properly assembled State value, but it's > > the wrong value. It's always the very first record in the State table > > regardless of the value in my StateID column in the Address table. > > > > My mapping as it stands now: > > public AddressMap() > > { > > Id(a => a.Id).Column("AddressID").GeneratedBy.Identity(); > > Map(a => a.City); > > Map(a => a.PostalCode); > > Map(a => a.Street1); > > Map(a => a.Street2); > > > > Join("State", join => > > { > > join.KeyColumn("StateID"); > > join.Component(a => a.State, m => > > { > > m.Map(x => x.Id).Column("StateID"); > > m.Map(x => x.Name); > > m.Map(x => x.ShortName).Column("ISO2"); > > }); > > }); > > > > } > > > > My presumption is that join.KeyColumn("StateID") is analogous to the > > ON clause of a JOIN statement. But it's not what I'm observing at the > > moment. > > -- > 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. > > -- 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.
