nhibernate mapping: A collection with cascade="all-delete-orphan" was no longer referenced -


I am getting some inquiry with my fluent mapping. I have a child collection of institutions, for example events and Events for example.

If I set all the cascade mappings in the collection to AllDeleteOrphan, then I get the following error when saving a new unit to DB: NHibernate .HibernateException: with cascade = "all-delete-orphan" The owner of a collection was not referred to the example instance: Core.Event.EventItems

If I set cascade to all, does this work properly? Below are my classes and mapping files:

  Public class EventMap: ClassMap & lt; Event & gt; {Public eventmap () {id (x => x.Id, "id"). Inappropriate value ("00000000-0000-0000-0000-000000000000") GeneratedBy.GuidComb (); Map (x = & x; x.Name); HasMany (x = & gt; x.EventItems). Inverted (.) Column ("EventID") .AsBag () .Cascade.AllDeleteOrphan (); }} Public Segment EventItemap: Subclass Map & lt; Event item & gt; {Public event itemmap () {id (x => x.Id, "id"). The value used ("00000000-0000-0000-0000-000000000000") GeneratedBy.GuidComb (); Reference (x => x.Event, "EventId"); }} Public Square Event: EntityBase {Private IList & lt; EventItem & gt; _EventItems; Safe Event () {InitMembers (); } Public Event (name of string): this () {name = name; } Private Zero InitMembers () {_EventItems = New list & lt; EventItem & gt; (); } Public Virtual Event Itam CreateEventItem (String Name) {Event Event Event Iatam = New Event Item (this, name); _EventItems.Add (eventItem); Return event item; } Public Virtual String {get} Private set; } Public Virtual Assistant & lt; Event item & gt; Event Items {get {return_EventItems.ToList & lt; EventItem & gt; (). AsReadOnly (); } Protected Set {_EventItems = value; }}} Public class EventItem: EntityBase {protected EventItem ()}} Public EventItem (event @ event, string name): base (name) {event = @event; } Received Public Virtual Event Event { Private set; }}  

Beautiful is stumped here. Any suggestions appreciated.

Check

You need to map _EventItems to use an access Strategy so that the NHibernate could use the private member instead of the property. You are getting this error because the archive reference is changed when the list is returned to the _EventItems.ToList & lt; EventItem & gt; () is copied to a new list. Try it out:

  Public class eventmap: classmap & lt; Event & gt; {Public eventmap () {id (x => x.Id, "id"). Inappropriate value ("00000000-0000-0000-0000-000000000000") GeneratedBy.GuidComb (); Map (x = & x; x.Name); HasMany (x = & gt; x.EventItems). Access Pascal Howffield (prefix. Underscore). Inverted (.) Column ("EventID"). Asbag () .Cascade.AllDeleteOrphan (); }}}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -