One reason not to map the Request in the RequestNote might be because you
want to Load a RequestNote without worrying about triggering a lazy load of
the Request, and subsequently the entire RequestNotes collection, right?
In your implementation, it is a bit curious to have the RequestNote
collection mapped as Cascade All, and then having to do the saving twice.
If I understand Oskar correctly, you should be able to get rid of the
requestNote.RequestID field, and instead replace it with a Request instance
property.
This then infers that instead of doing
var request = new Request();
session.Save(request);
var note = new RequestNote() { RequestID = request.ID };
request.Notes.Add(note);
session.Save(request);
you might do something instead like
var request = new Request();
var note = new RequestNote();
request.AddNote(note);
session.Save(request);
the AddNote method would look like:
note.Request = this;
this.Notes.Add(note)
I would think this would result in 1 fewer sql statement (the update for
the Request on the second save?)
However .. if you NEED to have the RequestID also in your Note model,
then you need to map it as a generated on insert (assuming a note can't be
changed to a dif request), OR have a read-only property that gets it off
the Request instance. (return this.Request.ID)
On Fri, Dec 16, 2011 at 2:22 PM, aric <[email protected]> wrote:
> how can i generate an id and only do save first ??
>
>
> On Dec 16, 10:50 am, Oskar Berggren <[email protected]> wrote:
> > 2011/12/16 aric <[email protected]>:
> >
> > > are you talking about this line ??
> >
> > > note.RequestID = request.RequestID;
> >
> > > I am not sure what you mean, can you show me ?
> >
> > Simply
> >
> > note.Request = request;
> >
> > /Oskar
>
> --
> 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.
>
>
--
Joe Brockhaus
[email protected]
--
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.