Wow, that's a fairly creative way to remove an item from a list. Try
just using one of the Remove() methods on the list. Something like
the following:
public virtual void RemoveDetail(ProductDetail productDetail)
{
// assuming productDetail is an object from the list, then
this is the simplest...
//productDetail.Product = nothing;
//ProductDetails.Remove( product );
// otherwise
var item = (from p in ProductDetails where p.Id ==
productDetail.Id select p).FirstOrDefault();
if(item!=null)
{
item.Product = null;
ProductDetails.Remove( item );
}
}
you can't just create a new ProductDetails collection since NH may
be tracking the old one using a proxy class.
On Sun, Sep 19, 2010 at 10:11 AM, Kris-I <[email protected]> wrote:
> Hello,
>
> I have a "Product" entity. A Product can have several "ProductDetail".
>
> I do this : product.AddDetail(new ProductDetail());
>
> The code is :
>
> public virtual void AddDetail(ProductDetail productDetail)
> {
>
> productDetail.Product = this;
> ProductDetails.Add(productDetail);
> }
>
> When I save no problem, the Product and ProductDetail are save.
>
> When I remove a "ProductDetail", I do this :
>
>
> product.RemoveDetail(myProductDetail);
>
> The code is :
>
> public virtual void RemoveDetail(ProductDetail productDetail)
>
> {
> ProductDetails = (from p in ProductDetails where p.Id != productDetail.Id select p).ToList<ProductDetail>();
>
> }
>
> The "ProductDetails" has the right content but when I update, I don't see
> inb NHProf any Delete.
>
> It's probably a trouble in the mapping file but I don't find the right
> configuration
>
>
> The mapping : http://pastebin.com/muaCXMvu
> The C# code : http://pastebin.com/YNeyjkJa
>
> Any idea ?
>
> Thanks,
>
>
> --
> 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.
>
--
thanks
cliff
--
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.