If you have a look, the AddEntityCriteria() is called from within a
for loop i.e. foreach (List<int?> entityIds in
collectionOfEntityIdsPerParameterLimitByEntityType[entityType])
{
-----
AddEntityCriter();
----
}
The reason is I want to OR the entitycriteria generated for each
List<int?> entityIds. Does that help? by the way, it works just fine,
but fails at following NHIbernate code in FlushEverything() in
SessionImpl.cs:
if (log.IsDebugEnabled)
{
log.Debug("Flushed: " +
insertions.Count + " insertions, " +
updates.Count + " updates, " +
deletions.Count + " deletions to " +
entityEntries.Count + " objects");
log.Debug("Flushed: " +
collectionCreations.Count + "
(re)creations, " +
collectionUpdates.Count + " updates,
" +
collectionRemovals.Count + " removals
to " +
collectionEntries.Count + "
collections");
new
Printer(factory).ToString(entitiesByKey.Values.GetEnumerator()); //
FAILS HERE
}
On Nov 11, 6:04 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote:
> I;m missing something how is lastExpression ever not null when you do this
> check:
>
> if (lastExpression == null)
> {
> lastExpression = entityExpression;
> }
>
> Jon
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jatin
> Sent: Monday, November 10, 2008 9:00 PM
> To: nhusers
> Subject: [nhusers] Re: System.InvalidOperationException. Collection was
> modified; enumeration operation may not execute
>
> This is the overloaded version with what you wanted. sorry for the
> confusion:
>
> private void AddEntityCriteria(ICriteria parentCriteria, string
> alias, string entityType, List<int?> entities)
> {
> if (entities.Count > 1)
> {
> string setAlias = "ASI";
> ICriteria entityCriteria =
> parentCriteria.CreateCriteria(
> string.Format("{0}.{1}", alias,
> enumAttributeInstance.AttributeSetInstance), setAlias,
> JoinType.InnerJoin);
>
> NHibernate.Expression.AbstractCriterion lastExpression
> = null;
>
> NHibernate.Expression.AbstractCriterion
> entityExpression = GetEntityExpression(setAlias, entityType,
> entities);
> if (lastExpression == null)
> {
> lastExpression = entityExpression;
> }
> else
> {
> lastExpression =
> NHibernate.Expression.Expression.Or(lastExpression, entityExpression);
> }
>
> entityCriteria.Add(lastExpression);
> }
> else if (entities.Count > 0)
> {
> int? entityId = entities[0];
> AddEntityCriteria(parentCriteria, alias, entityType,
> entityId);
> }
>
> }
>
> On Nov 11, 5:57 pm, Jatin <[EMAIL PROTECTED]> wrote:
> > Hi Jon,
>
> > This is from my original post. As you can see it has 3 parameters.
> > Could you send me source code where you see AddEntityCriteria with one
> > parameter. Thanks
>
> > // Add Entity Crieria
> > if (entityIds != null)
> > {
> > AddEntityCriteria(criteria, alias,
> > entityType, entityIds);
> > }
>
> > On Nov 11, 5:51 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote:
>
> > > From your original post it looks like there is a version of
> > > AddEntityCriteria that takes a List<int?> as a parameter.
>
> > > -----Original Message-----
> > > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of
> > > Jatin
> > > Sent: Monday, November 10, 2008 8:46 PM
> > > To: nhusers
> > > Subject: [nhusers] Re: System.InvalidOperationException. Collection was
> > > modified; enumeration operation may not execute
>
> > > Hi Jon
>
> > > Here is the AddEntityCriteria() source code.Pl let me know if u need
> > > any more info. Thanks
>
> > > private void AddEntityCriteria(ICriteria parentCriteria, string alias,
> > > string entityTypeName, int? entityId)
> > > {
> > > if (!string.IsNullOrEmpty(entityTypeName) ||
> > > entityId.HasValue)
> > > {
> > > string setAlias = "ASI";
> > > ICriteria entityCriteria =
> > > parentCriteria.CreateCriteria(
> > > string.Format("{0}.{1}", alias,
> > > enumAttributeInstance.AttributeSetInstance), setAlias,
> > > JoinType.InnerJoin);
>
> > > if (!string.IsNullOrEmpty(entityTypeName))
> > > {
> > > entityCriteria.Add(new
> > > NHibernate.Expression.EqExpression(
> > > string.Format("{0}.{1}", setAlias,
> > > enumAttributeSetInstance.EntityTypeName), entityTypeName));
> > > }
> > > if (entityId.HasValue)
> > > {
> > > entityCriteria.Add(new
> > > NHibernate.Expression.EqExpression(
> > > string.Format("{0}.{1}", setAlias,
> > > enumAttributeSetInstance.EntityId), entityId.Value));
> > > }
> > > }
> > > }
>
> > > On Nov 11, 5:38 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote:
> > > > What does AddEntityCriteria look like and how does it use the entryIds?
>
> > > > -----Original Message-----
> > > > From: [email protected] [mailto:[EMAIL PROTECTED] On
>
> > > > Behalf Of Jatin
> > > > Sent: Monday, November 10, 2008 6:38 PM
> > > > To: nhusers
> > > > Subject: [nhusers] System.InvalidOperationException. Collection was
> > > > modified; enumeration operation may not execute
>
> > > > 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>()));
> > > >
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---