I have one bit of denormalized data used for performance reasons and
I'm trying to maintain the data with an NHibernate event listener
rather than a trigger. I'm not convinced this is a good idea, but I
thought it would be a good way to learn more about NHibernate. Also I
was concerned about the 2nd level cache getting out of sync using a
trigger...
I get the following error:
System.InvalidOperationException : Collection was modified;
enumeration operation may not execute.
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource
resource)
System.Collections.Generic.List`1.Enumerator.MoveNextRare()
System.Collections.Generic.List`1.Enumerator.MoveNext()
NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
NHibernate.Engine.ActionQueue.ExecuteActions()
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource session)
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
event)
NHibernate.Impl.SessionImpl.Flush()
NHibernate.Transaction.AdoTransaction.Commit()
-----------------------------------------
using (var tx = session.BeginTransaction())
{
var business = session
.Get<Business>(1234)
.ChangeZipCodeTo("92011");
session.Update(business);
tx.Commit(); // error happens here
}
-----------------------------------------
public class UpdateBusinessCategoryLinks : IPostUpdateEventListener
{
public void OnPostUpdate(PostUpdateEvent @event)
{
var business = @event.Entity as Business;
if (business != null)
{
var links = @event.Session
.CreateQuery("select l from BusinessCategoryLink as l
where l.Business.BusinessId = :businessId")
.SetParameter("businessId", business.BusinessId)
.List<BusinessCategoryLink>();
foreach (var link in links)
{
link.Location = business.Location;
@event.Session.Update(link);
}
}
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---