Hi All

I get the following exception when using Criteria objects in
NHibernate. The error is only coming up in production and not in Dev
or UAT. I am stumped as cant replicate the error and need to fix this
asap. The error and the code resulting in the error are below. Any
help will be greatly appreciated. I am hitting the database multiple
times with the same Nhibernate session. Is that the problem. Thanks
Jatin.

The error :

Base exception:
System.InvalidOperationException
Collection was modified; enumeration operation may not execute.

Stack Trace:
   at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
   at NHibernate.Impl.Printer.ToString(IEnumerator enumerator)
   at NHibernate.Impl.SessionImpl.FlushEverything()
   at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet
querySpaces)
   at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList
results)
   at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
   at NHibernate.Impl.CriteriaImpl.List[T]()
   at
GrantEd.UtilityServices.ExtendedAttribute.AttributeInstancePathEvaluator.InternalEvaluate(List`1
entities) in C:\UserData\SEMISPT\Source\Development\UtilityServices
\ExtendedAttribute\GrantEd.UtilityServices.ExtendedAttribute\Controller
\AttributeInstancePathEvaluator.cs:line 121

The piece of code that results in the error:

public IAttributeInstances InternalEvaluate(List<KeyValuePair<string,
int?>> entities)
        {
            IAttributeInstances attributeInstances = new
AttributeInstances();
            using (ISession session =
NHibernateSessionManager.Instance.GetSession<AttributeInstance>(_session))
            {
                // Based on List<KeyValuePair<string, int?>> of
entities, Get a list per parameter limit
                //(1000 parameters for an IN condition) of List<int?>
entityIds.
                Dictionary<string, List<List<int?>>>
collectionOfEntityIdsPerParameterLimitByEntityType =
GetCollectionOfEntityIdsPerParameterLimitByEntityType(entities);

                string alias = "E";

                // In case no entities provided, still need to return
records matching
                // AttributePath
                if (entities == null || entities.Count == 0)
                {
                    ICriteria criteria =
InitialiseCommonCriteria(session);
                    return new
AttributeInstances(criteria.List<AttributeInstance>());
                }

                // foreach entityType - loop through each List
containg List<int?> items per parameter limit
                // and hit the database and load the
IAttributeInstances for each list. Then Merge it and when
                // looped through all return the merged
IAttributeInstances.
                // Note: The Reason of seperate hits to the database
with each list of 1000 or less parameters in
                // the IN condition is to meet the limitation of
parameter size in stored procedures which is                    //
2100. We had attempted to hit database in one go with seperate IN
conditions each with a 1000
                // parameters or less but that resulted in an error as
soon as number of parameters went to more
                // than 2100.

                foreach (string entityType in
collectionOfEntityIdsPerParameterLimitByEntityType.Keys)
                {
                    foreach (List<int?> entityIds in
collectionOfEntityIdsPerParameterLimitByEntityType[entityType])
                    {
                        ICriteria criteria =
InitialiseCommonCriteria(session);

                         // Add Entity Crieria
                        if (entityIds != null)
                        {
                            AddEntityCriteria(criteria, alias,
entityType, entityIds);
                        }

                        // Now that the criteria has been built
execute it to resolve the attribute instances
                        // and merge it to the running
IAttributeInstances List
                        attributeInstances.Merge(new
AttributeInstances(criteria.List<AttributeInstance>()));
                    }
                }
            }

            return attributeInstances;
        }



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to