I am using sharp arch ver 1.0.
In the NHibernate PostUpdateEvent I am trying to access database.
public class PostUpdateListener : IPostUpdateEventListener
{
public void OnPostUpdate(PostUpdateEvent postUpdateEvent)
{
var session = NHibernateSession.Current;
var results = session.CreateSQLQuery("Select * from Storefront").List<object>();
for (int i = 0; i < results.Count; i++)
{
}
}
When I try to save any entity and in the postupdateevent i run this select query, it gives the enumeration error on OnFlush. NHibernate\Listeners\FlushFixEventListener .cs Line: 35
I read that using foreach loop runs enumeration operation so better to run for loop. But I tried with the for loop. still makes no difference.
The save operation is processed with SharArch NHibernate Transaction attribute. If I remove the Transaction attribute the query in the postupdatelistener works fine.
here is the stack trace.
[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +56
System.Collections.Generic.Enumerator.MoveNextRare() +58
System.Collections.Generic.Enumerator.MoveNext() +93
NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\horn.horn\orm\nhibernate\Working-2.1\src\NHibernate\Engine\ActionQueue.cs:112
NHibernate.Engine.ActionQueue.ExecuteActions() in d:\horn.horn\orm\nhibernate\Working-2.1\src\NHibernate\Engine\ActionQueue.cs:147
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\horn.horn\orm\nhibernate\Working-2.1\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:241
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) in d:\horn.horn\orm\nhibernate\Working-2.1\src\NHibernate\Event\Default\DefaultFlushEventListener.cs:19
Infrastructure.NHibernate.Listeners.FlushFixEventListener.OnFlush(FlushEvent event) in D:\Solutions\Infrastructure\NHibernate\Listeners\FlushFixEventListener .cs:35
NHibernate.Impl.SessionImpl.Flush() in d:\horn.horn\orm\nhibernate\Working-2.1\src\NHibernate\Impl\SessionImpl.cs:1478
Infrastructure.NHibernate.LinqRepository1.Save(T entity) in D:\Solutions\Infrastructure\NHibernate\LinqRepository.cs:95
Tasks.Shared.ContentEntityTasks4.Save(TSaveEntityRequestDetails details) in D:\Solutions\Tasks\Shared\ContentEntityTasks.cs:96
Web.Controllers.Entity.EntityController.Edit(EntityViewModel entityViewModel, HttpPostedFileBase fileName, HttpPostedFileBase mainImageFileName, HttpPostedFileBase thumbnailFileName) in D:\Solutions\Web.Controllers\Entity\EntityController.cs:379
lambda_method(ExecutionScope , ControllerBase , Object[] ) +185
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +236
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +31
System.Web.Mvc.<>c_DisplayClassa.b_7() +85
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +235491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +235491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +235491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +235491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +288
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +235670
System.Web.Mvc.Controller.ExecuteCore() +174
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +209
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171