fel0niousmonk
unread,Feb 7, 2011, 12:50:39 PM2/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
this is a 3-part question:
1 - the correct usage of cascade
2 - the correct usage/interaction of/with the session: order & number
of saves, etc
3 - possibility for 2 save scenarios for the many-to-one side
(web) Application consists of Tickets & Notes for those tickets,
represented by the below domain.
there are 2 scenarios in which tickets and notes will be saved:
1. new Ticket is created, and new notes are added, all before saving
across the wire
1.a. when saved across the wire, all entities are available.
Ticket.Notes has all the notes, which all have valid Ticket instances
and TicketID values.
2. existing Ticket is edited, new notes are added.
1.a. when saved, because the Ticket isn't dirty, only the new Note
instances come back across the wire, which only have valid TicketID
values.
Now in scenario #2, because I've been led to believe that the Ticket
instance MUST exist prior to saving to the NHib session, I try to use
Session.Get<Ticket>(note.TicketID) or (if Get returned null)
Load<Ticket>(note.TicketID) to get either from the in-memory session
or from the database.
If I use cascade, does that mean I can NEVER save a Note instance
itself?
-- i.e. - I have to get/load the Ticket instance, set newNote.Ticket
== loadedTicket, then UPDATE the ticket?
for scenario #1, do I save all note instances AND the ticket?
-- Session.Save(newTicketWithNotes), Session.Save(newNote1),
Session.Save(newNote2) ... vs
-- Session.Save(newTicketWithNotes)
-- and if it's the former, must I save the ticket first or last?
public class Ticket
{
public int TicketID {get;set;}
public IList<Note> Notes = new List<Note>();
}
public class Note
{
public int NoteID {get;set;}
public Ticket Ticket {get;set;}
public int TicketID {get;set;}
}