Jide - very well put. You've also managed to condense other answers into
your in a nice, simple, and clear way to understand it. Bravo to you.

Cheers,
Alec Whittington
twitter: http://twitter.com/alecwhittington
<http://twitter.com/alecwhittington>blog: http://blog.sharparchitecture.net
Become a fan of S#arp Architecture on
Facebook<http://www.facebook.com/pages/Sarp-Architecture/117591724971997>




On Mon, Feb 7, 2011 at 5:08 PM, JideO <[email protected]> wrote:

> I think a little empathy for Joe's frustration is in order. Joe I
> think you should appologise to people you would have offended by
> taking out your frustration on them.
>
> I have also been on the receiving end of what initially seem to be
> unhelpful answers but later on when I understood the issues better, I
> find that one of the replies I had been frustrated with already
> contained the answer to my question.
>
> Even at this, there are still some questions I have on nhibernate and
> on other forums where I have given up on getting a direct answer
> saying "this is so and so" or "this was not designed to be used like
> so try using it like so" or even "you idiot, what were you thinking,
> that's not what that means but this is the correct meaning". This
> happens even on paid support forums so its not just the OS community.
> Bottom line is this Joe, when you've written a response in frustration
> take a few deep breaths to think it over before pressing the send
> button.
>
> I'm also learning nhibernate so I may be able to answer your questions
> at a level you'll understand. Sometimes the more experienced guys
> communicate in very condensed language, and unless you already
> understand the solution you may find it difficult understanding their
> explanation.
>
> With regards to the cascade option, from my (limited) experience when
> cascade is used on a class property it specifies what should happen to
> a transient instance of objects referred to by the entity when the
> session is eventually flushed or a transaction committed.
>
> eg
>
> if you have a parent object which has a collection of child objects
> and the child collection is defined with a cascade=save-update. If the
> parent object was retrieved from the db/session and you add a child
> object to the parents collection, when the session is flushed or (the)
> transaction is committed the child object will be saved without having
> to do a session.save on the child object.
>
> void dothis()
> {
>
>    ISession session = .....
>
>    ITransaction t = session.BeginTransaction();
>    var parent = session.Get<Parent>(10);
>    child = new child();
>    parent.addChild(child);             // or
> parent.children.add(child);
>    child.Parent = parent;              // for bidirectionality
>
>    t.Commit();                             // or session.flush();
>                                                 // the child object
> will be inserted although you did not
>                                                 // explicitly save it
> }
>
> If the parent object is also new, you have to call session.save on the
> parent object and all its children reachable by cascaded properties
> will be saved as well.
>
> void saveNewParentAndChildren()
> {
>    var parent = new Parent();
>    var child = new Child();
>    parent.addChild(child);
>    child.Parent = parent;
>
>    var session = .... get your session
>    session.Save(parent);
>    session.Flush();                         // this will insert
> cascaded child objects as well
> }
>
> Another aspect which you seem to be missing is that you are referring
> to TicketID in your object model. This is not what is intended. You
> should not have to deal with the TicketID in your note class instead
> you would be referring to the Ticket object instead.
>
> Instead of having
>
> class Note
> {
>     long TicketID;
>     string Text;
> }
>
> what you should have is
>
> class Note
> {
>     Ticket ticket;
>     string text;
> }
>
> Your mapping is where you would specify the column to be used in the
> Note table to store the ticket's id.
>
> The third thing you seem to have trouble with is this issue of
> managing of the references yourself. If you are connecting object
> together nhibernate does not help you manage the object references on
> newly created connections. i.e. if you have a parent object and want
> to add a child object to it you will need to in YOUR code do
> parent.addChild(child) and child.Parent = parent, if you want a
> bidirectional association.
>
> Does this help.
>
> Jide
>
> On Feb 4, 9:42 pm, Joe Brockhaus <[email protected]> wrote:
> > no one is willing to address this, eh?
> >
> > must be too simple of a problem. but alas, it is not.
> > the behavior I'm seeing is both inconsistent, and routinely unexpected
> given
> > common sense.
> >
> > for more context, please see:
> http://groups.google.com/group/fluent-nhibernate/browse_thread/thread...
> >
> > yes, i'm using Fluent for my mappings.
> > yes, I can get you the HBM if you absolutely need it.
> > yes, i'm confident that my problems are both a consequence of not mapping
> > Fluent correctly, and also correct mappings resulting in unexpected NHib
> > behavior.
> >
> > one such issue that does not seem to differ regardless of how I map my
> > entities:
> > -- Does NHib require me to add entities to the Session in the order in
> which
> > they need to be saved to correctly reference a one-to-many/many-to-one
> > association? For instance, if I have a Ticket instance which has mapped
> an
> > IList<Note> ... I'm seeing that if I add 3 Note instances, which have
> valid
> > Ticket instances references and valid Note.TicketID values, to the
> Session
> > BEFORE adding the Note.Ticket instance, then BeginTransaction().Commit ..
> > NHib fails on insert (Note.TicketID is an invalid FK, oracle error, as
> the
> > TicketID column has a FK constraint). If I add the Ticket first, the save
> > works, but the Note instances in the cache are not updated with the
> TicketID
> > generated in Oracle. The database has correct values, but this means that
> if
> > I Load<Ticket>(ticketID) again, Ticket.Notes(0).TicketID, for instance,
> is
> > still 0 -- the value it had BEFORE the transaction was committed.
> >
> > Thanks for your help ....
> >
> > ------
> > Joe Brockhaus
> > [email protected]
> > ------------
> >
> >
> >
> > On Wed, Feb 2, 2011 at 7:14 PM, fel0niousmonk <[email protected]>
> wrote:
> > > background:
> > > -- the database is Oracle.
> > > -- PKs for both tables (TICKETS, NOTES) are generated by sequences
> > > (SEQ_TICKET_ID, SEQ_NOTE_ID)
> > > -- Silverlight & RIA Services
> >
> > > question:
> > > -- given the following, what should my mapping look like?
> >
> > > public class Ticket
> > > {
> > >   [Key]
> > >   public int TicketID {get;set;}
> >
> > >   [Include]
> > >   [Association("Ticket_Notes",
> > >            "TicketID",
> > >            "TicketID"]
> > >   public IList<Note> Notes = new List<Note>();
> > > }
> > > public class Note
> > > {
> > >   [Key]
> > >   public int NoteID {get;set;}
> >
> > >   [Include]
> > >   [Association("Note_Ticket",
> > >            "TicketID",
> > >            "TicketID",
> > >            IsForeignKey = true)]
> > >   public Ticket Ticket {get;set;}
> > >   public int TicketID {get;set;}
> > > }- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.
>
>

-- 
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.

Reply via email to