Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 850221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:13:48+00:00 2026-05-15T07:13:48+00:00

I would like to delete the ICollection PriceBreaks from Product. I’m using the following

  • 0

I would like to delete the ICollection PriceBreaks from Product.

I’m using the following method. However they dont seem to delete. What am i missing.
When i step thru. i notice that “product.PriceBreaks.Clear();” doesn’t actually clear the items. Do i need to flush or something?

public void RemovePriceBreak(int productId)
{

using (ISession session = EStore.Domain.Helpers.NHibernateHelper.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
    var product = session.Get<Product>(productId); 
   // i can see 20 PriceBreak records, tho nh prof saids PriceBreak table hasn't been hit
    product.PriceBreaks.Clear();
    session.SaveOrUpdate(product);
    transaction.Commit(); // PriceBreak table is hit here with select statement, no delete?
}

}

Here are my hbm files

  <class name="Product" table="Products">
    <id name="Id" type="Int32" column="Id" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name="CompanyId" column="CompanyId" type="Int32" not-null="true" />
    <property name="Name" column="Name"/>
    <set name="PriceBreaks" table="PriceBreaks" generic="true" cascade="all-delete-orphan" inverse="true" >
      <key column="ProductId" />
      <one-to-many class="EStore.Domain.Model.PriceBreak, EStore.Domain" />
    </set>    
  </class>



<class name="PriceBreak" table="PriceBreaks">
    <id name="Id" type="Int32" column="Id" unsaved-value="0">
      <generator class="identity"/>
    </id> 
    <many-to-one name="Product" column="ProductId"  not-null="true"  class="EStore.Domain.Model.Product, EStore.Domain" />    
  </class>

My Entities

 public class Product
    {

        public virtual int Id { get; set; }
    public virtual ICollection<PriceBreak> PriceBreaks { get; set; }
        public virtual void AddPriceBreak(PriceBreak priceBreak)
        {
            priceBreak.Product = this;
            PriceBreaks.Add(priceBreak);
        }
    }




 public class PriceBreak
    {
        public virtual int Id { get; set; }
        public virtual Product Product { get; set; }  
    }

Here is the sql from nhprof

//
SELECT product0_.Id as Id0_0_
FROM Products product0_
WHERE product0_.Id = 23 /* @p0 */

and then

SELECT pricebreak0_.ProductId as ProductId1_,
pricebreak0_.Id as Id1_,
pricebreak0_.Id as Id1_0_,
pricebreak0_.ProductId as ProductId1_0_,
FROM PriceBreaks pricebreak0_
WHERE pricebreak0_.ProductId = 23 /* @p0 */

there is no update or select

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:13:48+00:00Added an answer on May 15, 2026 at 7:13 am

    Product probably needs to be associated with that session. It looks like you are trying to save a detached object. Which means there is no session to track that call to clear the PriceBreaks. Change it to this…

    public void RemovePriceBreak(int productId)
    {
    
        using (ISession session = EStore.Domain.Helpers.NHibernateHelper.OpenSession())
        using (ITransaction transaction = session.BeginTransaction())
        {
            var product = session.Get<Product>(productId);
            product.PriceBreaks.Clear();
            session.SaveOrUpdate(product);
            transaction.Commit();
        }
    }
    

    or move the session and transaction management further up. Which would basically eliminate the need for this method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that logs using log4net. But we would like to delete
I would like to know can we delete cookie from cookies collection what we
I would like to delete all the rows found by that query: SELECT cart_abandon.*
I would like to delete every double space in a file open in vim,
I would like to delete all the links in a quicklaunch in SP2010 with
I would like to run a timer for every 5 hours and delete the
I would like to bind an Image to some kind of control an delete
I would really like your help in knowing the procedure to delete a .3gp
I have the following javascript: $.post(/Authenticated/DeletePage/ + PageId); showStatus(Page deleted..., 10000); I would like
and it's linked to a 'confirm comment deleted page. Ideally I would like it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.