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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:54:41+00:00 2026-05-13T12:54:41+00:00

I am having some probs with my fluent mappings. I have an entity with

  • 0

I am having some probs with my fluent mappings. I have an entity with a child collection of entities i.e Event and EventItems for example.

If I set my cascade mapping of the collection to AllDeleteOrphan I get the following error when saving a new entity to the DB:
NHibernate.HibernateException : A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance: Core.Event.EventItems

If I set the cascade to All it works fine? Below are my classes and mapping files:

 public class EventMap : ClassMap<Event>
{
    public EventMap()
    {
        Id(x => x.Id, "Id")
            .UnsavedValue("00000000-0000-0000-0000-000000000000")
            .GeneratedBy.GuidComb();

        Map(x => x.Name);
        HasMany(x => x.EventItems)
            .Inverse()
            .KeyColumn("EventId")
            .AsBag()
            .Cascade.AllDeleteOrphan();
    }
}

  public class EventItemMap : SubclassMap<EventItem>
{
    public EventItemMap()
    {
         Id(x => x.Id, "Id")
            .UnsavedValue("00000000-0000-0000-0000-000000000000")
            .GeneratedBy.GuidComb();
        References(x => x.Event, "EventId");
    }
}



public class Event : EntityBase
{
    private IList<EventItem> _EventItems;

    protected Event()
    {
        InitMembers();
    }

    public Event(string name)
        : this()
    {
        Name = name;
    }

    private void InitMembers()
    {
        _EventItems = new List<EventItem>();
    }

    public virtual EventItem CreateEventItem(string name)
    {
        EventItem eventItem = new EventItem(this, name);
        _EventItems.Add(eventItem);
        return eventItem;
    }

    public virtual string Name { get; private set; }
    public virtual IList<EventItem> EventItems
    {
        get
        {
            return _EventItems.ToList<EventItem>().AsReadOnly();
        }
        protected set
        {
            _EventItems = value;
        }
    }
}

    public class EventItem : EntityBase
{
    protected EventItem()
    {
    }

    public EventItem(Event @event, string name):base(name)
    {
        Event = @event;
    }

    public virtual Event Event { get; private set; }
}

Pretty stumped here. Any tips greatly appreciated.

Chev

  • 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-13T12:54:42+00:00Added an answer on May 13, 2026 at 12:54 pm

    You need to map _EventItems using an access strategy so that NHibernate access the private member instead of the property. You’re getting this error because the collection reference is changed when the list is copied to a new List in _EventItems.ToList<EventItem>(). Try this:

    public class EventMap : ClassMap<Event>
    {
        public EventMap()
        {
            Id(x => x.Id, "Id")
                .UnsavedValue("00000000-0000-0000-0000-000000000000")
                .GeneratedBy.GuidComb();
    
            Map(x => x.Name);
            HasMany(x => x.EventItems)
                .Access.PascalCaseField(Prefix.Underscore)
                .Inverse()
                .KeyColumn("EventId")
                .AsBag()
                .Cascade.AllDeleteOrphan();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some trouble with what should be a very simple scenario. For example purposes,
I´m having some trouble retrieving a collection of strings in a projection: say that
Well I have a view of this type of hierarchy Main View (having some
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Basically having some trouble with using Hover to hide or show an item. The
Im having some problems getting the Sticky Footer to work on my site. If
Been having some trouble implementing a single-column index in LaTeX. I've been employing the
im having some difficulty trying to pull out a specific value from a cookie.

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.