Not sure if this will fix your issue, but since you have a PageNumber that
needs to be kept consistent, why don't you use a list instead of a bag?

   Diego


On Mon, Jan 11, 2010 at 18:53, Ryan Medlin <[email protected]> wrote:

> We have a bag of ContentPages where the PageNumber is unique in the
> database.
>
> When we remove one item form the list and then renumber the
> PageNuimbers and try to save it it first tries to update the
> PageNumbers in the database and we get an error since there is a
> unique contraint..
>
> What we want is for nHinbernate to Delte the item that is no longer in
> the list first and then do the update but hNibernate is trying to do
> the update first..this seem slike a very odvious thing so what are we
> missing here?
>
> Thanks in advance
>
> ======================================
>
>
>
> Related Code:
>
> Here is the contentItem mapping file for this bag:
>
>    <bag name="ContentPages" table="ContentPage" inverse="true"
> lazy="false" order-by="PageNumber" cascade="all-delete-orphan">
>      <key column="ContentItemId" not-null="true"/>
>      <one-to-many class="ContentPage"></one-to-many>
>
>    </bag>
>
>
> Here is the code to add and remove an item:
>
>
>        /// <summary>
>        /// add content page to the list of content pages
>        /// </summary>
>        /// <param name="contentPage">content page to be added</param>
>        public virtual void AddContentPage(ContentPage contentPage)
>        {
>            contentPage.ContentItem = this;
>            contentPage.PageNumber = this.contentPageNumber++;
>            this.contentItemToPageList.Add(contentPage.PageNumber,
> contentPage);
>
>            // this.ContentPages =
> this.contentItemToPageList.Values.ToList();
>            if (this.ContentPages == null)
>            {
>                this.ContentPages = new List<ContentPage>();
>            }
>            this.ContentPages.Add(contentPage);
>        }
>
>        /// <summary>
>        /// add content page to the list of content pages
>        /// </summary>
>        /// <param name="contentPage">content page to be added</param>
>        public virtual void RemoveContentPage(ContentPage contentPage)
>        {
>            this.ContentPages.Remove(contentPage);
>            this.contentPageNumber = (short)(this.ContentPages.Count +
> 1);
>        }
>
>
> Here is the contentPage mapping file:
>
> <?xml version="1.0"?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-
> import="true"
>  namespace="EET.DomainModel.Entities"
>  assembly="EET.DomainModel">
>  <class name="ContentPage" table="ContentPage" lazy="false">
>    <id
>    name="ContentPageId"
>    column="ContentPageId"
>    type="int">
>      <generator class="identity"/>
>    </id>
>    <many-to-one name="ContentItem" column="ContentItemId" not-
> null="true" ></many-to-one>
>    <property name="PageNumber" column="PageNumber" type="short" not-
> null="true" />
>    <property name="Title" column="Title" type="String"/>
>    <property name="Body" column="Body" type="String" not-null="true"/
> >
>    <property name="PreviousPageTeaser" column="PreviousPageTeaser"
> type="String"/>
>    <property name="NextPageTeaser" column="NextPageTeaser"
> type="String"/>
>  </class>
> </hibernate-mapping>
>
> --
> 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