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 1022783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:31:00+00:00 2026-05-16T11:31:00+00:00

i’m trying to remove an item from a one to many list and have

  • 0

i’m trying to remove an item from a one to many list and have it persist in the database. Here are the entities i have defined:

public class SpecialOffer
{
    public virtual int SpecialOfferID { get; set; }
    public virtual string Title { get; set; }
    public virtual IList<SpecialOfferType> Types { get; private set; }

    public SpecialOffer()
    {
        Types = new List<SpecialOfferType>();
    }
}

public class SpecialOfferType
{
    public virtual SpecialOffer SpecialOffer { get; set; }
    public virtual Type Type { get; set; }
    public virtual int MinDaysRemaining { get; set; }

    #region composite id requirements
    public override bool Equals(object obj)
    {
        if (obj == null || !(obj is SpecialOfferType))
            return false;

        var t = (SpecialOfferType)obj;

        return SpecialOffer.SpecialOfferID == t.SpecialOffer.SpecialOfferID && Type.TypeID == t.Type.TypeID;
    }

    public override int GetHashCode()
    {
        return (SpecialOffer.SpecialOfferID + "|" + Type.TypeID).GetHashCode();
    }
    #endregion
}

public class Type
{
    public virtual int TypeID { get; set; }
    public virtual string Title { get; set; }
    public virtual decimal Price { get; set; }
}

With the following fluent mappings:

public class SpecialOfferMap : ClassMap<SpecialOffer>
{
    public SpecialOfferMap()
    {
        Table("SpecialOffers");
        Id(x => x.SpecialOfferID);
        Map(x => x.Title);
        HasMany(x => x.Types)
            .KeyColumn("SpecialOfferID")
            .Inverse()
            .Cascade.All();
    }
}

public class SpecialOfferTypeMap : ClassMap<SpecialOfferType>
{
    public SpecialOfferTypeMap()
    {
        Table("SpecialOfferTypes");
        CompositeId()
            .KeyReference(x => x.SpecialOffer, "SpecialOfferID")
            .KeyReference(x => x.Type, "TypeID");
        Map(x => x.MinDaysRemaining);
    }
}

public class TypeMap : ClassMap<Type>
{
    public TypeMap()
    {
        Table("Types");
        Id(x => x.TypeID);
        Map(x => x.Title);
        Map(x => x.Price);
    }
}

The problem i have is that if i remove an item from the SpecialOffer.Types collection it successfully removes it from the list but when i try to save the session the change is not persisted in the database. I’m assuming this is something to do with the composite id on the join table since i have been able to do this successfully in the past with a standard id.

I’d appreciate it if someone could show me what i’m doing wrong. Thanks

  • 1 1 Answer
  • 1 View
  • 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-16T11:31:01+00:00Added an answer on May 16, 2026 at 11:31 am

    I think you have to 1) Change the cascade setting on SpecialOffer.Types to Cascade.AllDeleteOrphan() and 2) set SpecialOfferType.SpecialOffer = null when you remove it from the collection. Since the collection is the inverse side of the relationship, the many-to-one reference to SpecialOffer on SpecialOfferType has to be set to null to make it an orphan, then Cascade.AllDeleteOrphan will cause it to be deleted.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.