The reason I asked about KeyColumn, Column, and ForeignKey, was because
originally, I could not get loading to work without specifying all of them.
It seemed odd to me that if I have the KeyColumn set on the HasMany to the
correct column for TicketMap, that I would not also need to define it on the
NoteMap. After reading the ForeignKey documentation, it doesn't make sense
to me that i needed it, as I'm not generating schema. So idk.

For LazyLoading ... perhaps I'm misunderstanding the consequences it will
have on my architecture. With my Ticket.Notes example, when I
Session.Query<Ticket>() .. I'll get back a set of all Tickets, and *no* notes?
Then when RIA Services sends those all across the wire, will NHib do loads
for all those Notes because in order for RIA to serialize the items, it has
to read the collection, which spawns the loading? If that's the case, I
suppose it's not a big deal. But if I close the NHib Session before the
method completes, then it won't be able to LazyLoad, right? (Perhaps I
should be maintaining the Session across service requests?)

Inverse ... sounds like what you're saying is the reason for my problems
with respect to the order in which I save entities to the Session. Perhaps
this question is rhetorical given the duplication needed for
KeyColumn/Column, but .. If I *don't *specify Inverse on the HasMany<Note>,
does that mean that the Note Reference inherently infers Inverse?
-- "* but with the inverse set if there's a collection it may save the
children first (or the inverse) depending on your setting"*
---- if I 'set' HasMany().Inverse() ... then the items in that collection
will get saved first? afaik, there is only one way to 'set' inverse, and
that's on the HasMany().

---------------------------------------------------------
Here's a problem that must be common:
-- Given my mappings, minus the ForeignKey(..) on the References() in
NoteMap ..
1) Create and save a Ticket, with 3 Notes
2) In a different session, Load the entity
2) notice, after the load (this is lazy off) that the Ticket has 3 Note
instances in its Notes collection. perfect!
3) however, inspecting the Note instances, observe that, while the Note was
loaded and references correctly the Ticket, the TicketID field is 0.
4) to fix this, map the TicketID field using Map()
5) repeat step 1)
6) notice that the save fails, as nHib is trying to add an additional
parameter to the generated insert statement, and the params are all out of
order from with respect to the insert.
7) the fix? AFAIK, you have to map TicketID, and mark the References with
Not.Insert().

Is that expected? Is there another, better way to solve this? Just seems
counter-intuitive...but I suppose if you were foreign-keying off a column
that you weren't mapping, then you wouldn't want to force References() to
have an expression to map the field?


------
Joe Brockhaus
joe.brockh...@gmail.com
------------


On Fri, Feb 4, 2011 at 5:35 AM, James Gregory <jagregory....@gmail.com>wrote:

> You would do well to read the NHibernate documentation, as it covers a lot
> of your questions.
> http://www.nhforge.org/doc/nh/en/index.html There's a large section on
> collection mapping:
> http://www.nhforge.org/doc/nh/en/index.html#collections
>
> 1) What is the difference between AsBag() and AsList(), and how can i use
> AsList()? Should I?
>
> A bag is an unordered collection. A list is a collection with an explicit
> index for each item.
>
> 2) Are the KeyColumn, Column, and ForeignKey all required? What do the
> various combinations of these methods mean?
>
> No, they are not. Fluent NHibernate uses (mostly sensible) defaults for all
> these. You only need to specify them if you're changing the defaults.
> KeyColumn is used to specify the column used to join the two tables (the
> foreign key column in your child table). Column, I assume is on References,
> is the same as KeyColumn on collections (arguably inconsistently named), and
> ForeignKey is for specifying the foreign key constraint name used in schema
> generation.
>
> 3) If I use Not.LazyLoad() on NoteMap, do I need to use it on HasMany()?
>
> It's up to you. You don't need to do anything. If you do it on both, then
> it won't matter which entity gets loaded. If you only do it on one, when you
> load the other entity the relationship will be lazy. I strongly urge you not
> to disable lazy loading.
> http://ayende.com/Blog/archive/2010/08/04/nhibernate-is-lazy-just-live-with-it.aspx
>
> 4) What takes precedent for Cascade, when it's set on both? What does that
> really mean in both cases (on the HasMany & References, respectively)?
>
> Same as with lazy. The cascade used will be the one on the entity being
> saved.
>
> 5) How does Inverse affect the save behavior? Is it appropriate for all
> cases?
>
> Inverse specifies which side of the collection is responsible for saving.
> This can be considered a kind of override to the default saving behaviour
> (of saving which ever entity you call Save with on the Session). Normally
> NHibernate will just save whatever you call Save with, but with the inverse
> set if there's a collection it may save the children first (or the inverse)
> depending on your setting. Decide which entity can be considered the owner
> of the relationship and set inverse appropriately.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to fluent-nhibernate@googlegroups.com.
> To unsubscribe from this group, send email to
> fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
> .
> 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 fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to