We're currently using Version 6.0.4
We're have an intermittent, unusual problem while performing a refresh of data. In short, the client is requesting that the server perform a possibly 'long' operation. The server does it's processing asyncronously, adding/modifying around 90 Units to our table, with the possibility of hundreds of UnitCycles and SourcingDecisions. The server finishes, saves, and the async call is complete. The client now has to query for all the newly added entities.
Our Original Code (executed when the server operation is complete):
IEntityQuery<Unit> query = _entityManager.Units
.Where(i => i.COA.UniqueID == coaID)
.Include("SourcingDecisions")
.Include("SourcingDecisions.UnitCycle")
.Include("UnitCycles")
.Include("UnitCycles. Unit")
.With(QueryStrategy.DataSourceOnly);
_entityManager.ExecuteQueryAsync<Unit>(query, (args) =>
{
Refetched_Entities(args.Results);
}, null);
The problem we're having is that occassionally we get an Exception in the callback args from the query indicating that "An entity with this key: Unit: 8412cc8a-0c6d-4c83-9c59-01c9049be817 already exists in this EntityManager". What's odd to us about the error message is we're not Adding a new Unit to the entity manager with a duplicate key, we're simply querying for data... who cares if the Unit with that key is already in cache; if it is it's the same Unit, we just want a fresh copy of it.
Even more oddness. To attempt to get around the problem we added the following code before the query.
EntityState removeState =
EntityState.Added | EntityState.Deleted | EntityState.Detached | EntityState.Modified | EntityState.Unchanged;
_entityManager.RemoveEntities(typeof(SourcingDecision), removeState);
_entityManager.RemoveEntities(typeof(UnitCycle), removeState);
_entityManager.RemoveEntities(typeof(Unit), removeState);
So at this point, the cache should be completely cleared of all Units and yet, we still will receive the same Exception.
Any help would be appreciated.
The Exception:
System.Reflection.TargetInvocationException was unhandled by user code
Message=An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
StackTrace:
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at IdeaBlade.EntityModel.EntityQueriedEventArgs`1.get_Results()
at IdeaBlade.EntityModel.EntityQueryOperation`1.get_Results()
at AST.Web.SourcingCOA.SL.COAUnitDataManager.<RefetchData>b__0(EntityQueryOperation`1 args)
at IdeaBlade.EntityModel.EntityQueryOperation`1.IdeaBlade.EntityModel.IHasAsyncEventArgs.OnCompleted()
at IdeaBlade.EntityModel.AsyncProcessor`1.<>c__DisplayClass2.<.ctor>b__0(TArgs args)
at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)
InnerException: System.InvalidOperationException
Message=An entity with this key: Unit: 8412cc8a-0c6d-4c83-9c59-01c9049be817 already exists in this EntityManager
StackTrace:
at IdeaBlade.EntityModel.EntityGroup.AddToKeyMap(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityGroup.AddEntityCore(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityGroup.AddNewEntity(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityManager.AddEntityWrapper(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityReferenceBase.AttachIfPossible(EntityWrapper newValueWrapper)
at IdeaBlade.EntityModel.RelatedEntityList`1.AddOrInsert(Int32 index, T item, Boolean updateInverse)
at IdeaBlade.EntityModel.RelatedEntityList`1.Add(T item, Boolean updateInverse)
at IdeaBlade.EntityModel.ListEntityReference`1.AddEntity(Object entity, Boolean updateInverse)
at IdeaBlade.EntityModel.ListEntityReference`1.FixupReferences()
at IdeaBlade.EntityModel.EntityWrapper.<FixupReferences>b__13(EntityReferenceBase eref)
at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
at IdeaBlade.EntityModel.EntityWrapper.FixupReferences()
at IdeaBlade.EntityModel.EntityWrapper.TrackChanged(EntityChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.AddQueriedEntity(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityGroup.LoadEntity(EntityWrapper sourceWrapper, MergeStrategy mergeStrategy, Boolean& rowUpdated)
at IdeaBlade.EntityModel.EntityMerger.MergeEntityCore(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup)
at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.FindOrMergeTarget(EntityWrapper sourceWrapper, NavigationEntityProperty navProp, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.MergeScalarNavProp(EntityReferenceManager sourceRefManager, NavigationEntityProperty navProp, EntityReferenceBase targetSref, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.MergeNavProperties(InProcessInfo inProcessInfo, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.MergeEntityNavProperties(InProcessInfo inProcessInfo, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
at IdeaBlade.EntityModel.EntityMerger.<>c__DisplayClass1.<MergeEntities>b__0(EntityWrapper sourceWrapper)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
at IdeaBlade.EntityModel.DataBlockFns.MakeResultList(Type type, IEnumerable items, Boolean isOrdered)
at IdeaBlade.EntityModel.EntityQueryResult.UpdateDataSet(EntitiesDataBlock block, NavigationContext context)
at IdeaBlade.EntityModel.EntitiesDataBlock.Resolve(EntityQueryResult helper)
at IdeaBlade.EntityModel.EntityQueryResult..ctor(DataQueryResult dataQueryResult, EntityManager entityManager, MergeStrategy mergeStrategy, Guid queryId, QueryInfo queryInfo)
at IdeaBlade.EntityModel.EntityQueryResultCollection..ctor(DataQueryResultCollection dqResults, EntityManager entityManager, MergeStrategy mergeStrategy)
at IdeaBlade.EntityModel.EntityManager.MergeAndReturnDataSourceOnly(IEntityFinder finder, DataQueryResultCollection dqResults)
at IdeaBlade.EntityModel.EntityManager.ProcessFetchedData(DataQueryResultCollection dqResults, IEntityFinder finder)
at IdeaBlade.EntityModel.EntityManager.AsyncFetchCompleted(AsyncEventArgs args)
at IdeaBlade.EntityModel.EntityManager.<ExecuteQueryAsyncCore>b__57[T](EntityQueryOperation`1 op)
at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)
InnerException: