No. The relationship doesn't have to be bidirectional. Since you didn't
specify, I assumed this is what you wanted.

Please share your code and mappings, and we'll get you fixed up.

On Fri, Aug 13, 2010 at 2:37 AM, Niclas Pehrsson <[email protected]> wrote:

> I have the cascade set to all-delete-orphan, maybe it should be
> all,delete-orphan that you have written or is it just an spelling
> error? :)
> I have tried to have an many-to-one relation on the InvoiceEntry but
> with no success, but I may have done an mistake, but am I really
> forced to have an relation on the child?
>
> On Aug 12, 8:50 pm, Jason Dentler <[email protected]> wrote:
> > I am a bit confused about your question, but I'll answer the question I
> > think you asked
> >
> > You seem to be confusing inverse with cascade. The two are separate,
> almost
> > entirely unrelated concepts. I will assume you are talking about a
> > bidirectional one-to-many relationship where the many side is a set.
> >
> > You have
> >
> > public class Invoice
> > {
> >    protected virtual ISet<InvoiceItem> Items { get; set; }
> >    public virtual bool AddItem(Invoiceitem newItem)
> >    public virtual bool RemoveItem(InvoiceItem itemToRemove)
> >
> > }
> >
> > public class InvoiceItem
> > {
> >    public virtual Invoice Invoice { get; protected set; }
> >
> > }
> >
> > When mapping invoice's items collection, use cascade="all" (or better
> yet,
> > "all,delete-orphan") and inverse="true".
> >
> > Since the database only represents the one-to-many with the
> > [InvoiceItem].[InvoiceId] field, and the model represents each "side" of
> the
> > one-to-many with a reference, NHibernate will ignore one side.
> > inverse="true" means to look at invoiceItem.Invoice to fill
> > [InvoiceItem].[InvoiceId]. You should still keep both sides "in sync" in
> > your model. Don't be sloppy.
> >
> > Cascade means when NHibernate flush (insert/update/delete) the invoice,
> it
> > will automatically include each child invoice item.
> >
> > On Thu, Aug 12, 2010 at 11:07 AM, Niclas Pehrsson <[email protected]
> >wrote:
> >
> > > My dream scenario in code is to be able to do the following code.
> >
> > > var invoice = new Invoice();
> > > invoice.AddEntry(new InvoiceEntry("Title", unitPrice, quantity);
> > > session.Save(invoice);
> >
> > > And then all the invoice entries will be saved with the invoice.
> >
> > > As I have read and tried that isn't the most efficient way to do it
> > > because then I will be forced to use inverse="false" cause if it would
> > > be true the entries would not be associated with the invoice.
> > > And if I use inverse="false" I will get some unnecessary Update
> > > queries.
> >
> > > Can NHibernate in any way do so I can do as my code example above and
> > > just take the Id (Guid) generated for the invoice and take with it in
> > > the insert queries for the entries?
> >
> > > --
> > > 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]<nhusers%[email protected]>
> <nhusers%[email protected]<nhusers%[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]<nhusers%[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