Print Page | Close Window

InvalidOperationException thrown accessing Get of a Navigation Property

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2234
Printed Date: 25-Jan-2026 at 3:48am


Topic: InvalidOperationException thrown accessing Get of a Navigation Property
Posted By: HunterMayer
Subject: InvalidOperationException thrown accessing Get of a Navigation Property
Date Posted: 15-Oct-2010 at 1:31pm
I am getting an exception being thrown when a calling 'Get' (on a navigation property) when the child's FK is also it's PK (0-1 <-> 1 [pk of table]). I am also getting this with self referential associations (and assuming that it is supported since the EDM picked it up).

Here is the stack trace when the navigation property was accessed. Which was hard to track down, because it was being accessed because the entities properties were individually bound to an interface grid cell (the get call to the navigation property popped the exception). As the stack trace below illustrates it really doesn't get past the get call.

This table has a FK key back to a another table and that happens to be the pk of the table too. I don't get to control that... but I have to deal with it... :P

Is 5.0.6 my fix? I am using 5.0.3 right now. Is 5.0.5 a fix? I am going to try in any case (nothing left to do...).

Do let me know if you can use any more info.

===Stack Trace===
System.InvalidOperationException occurred
  Message=You may not change the entity’s EntityKey (currently ‘ElementHistory: -9223372036854747107’) while any of its related, dependent entities are in the entity cache. Are you sure you want to change the EntityKey? Consider reordering your operations such that you set the EntityKey first. Alternatively you could detach the entity or remove its dependent entities before trying again but be aware that you risk orphaning the dependent entities.
  Source=IdeaBlade.EntityModel
  StackTrace:
       at IdeaBlade.EntityModel.ScalarEntityReference`1.UpdateOtherProperties(EntityRelationLink relationLink, EntityWrapper fromEntity, EntityWrapper toEntity)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.UpdateFkForNewToEntity(EntityWrapper toEntity)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.SetEntity(T newValue, Boolean updateFkValues, Boolean updateInverseValues)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.AddEntity(Object entity, Boolean updateInverseValues)
       at IdeaBlade.EntityModel.RelatedEntityList`1.AddInverse(T otherEntity)
       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.<>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.ExecuteFetch(IEntityFinder finder)
       at IdeaBlade.EntityModel.EntityKeyFinder.Execute()
       at IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)
       at IdeaBlade.EntityModel.EntityManager.ExecuteQuery(IEntityQuery query)
       at IdeaBlade.EntityModel.EntityManager.FirstOrNullEntity(IEntityQuery query)
       at IdeaBlade.EntityModel.EntityQueryExtensions.FirstOrNullEntity(IEntityQuery query)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.QueryForEntity(EntityReferenceStrategy strategy)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.GetEntity(EntityReferenceStrategy strategy)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.GetValue()
       at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.<.ctor>b__0(NavigationEntityPropertyGetInterceptorArgs`2 args)
       at IdeaBlade.Core.PropertyInterceptor`3.HandleAction(Action`1 action, TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.<BuildTargetedCombinedAction>b__3(TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.ExecuteActions(TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.GetValue(TInstance instance, Object context)
       at IdeaBlade.Core.PropertyInterceptor`3.GetValue(TInstance instance)
       at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.GetValue(TInstance instance)
       at Dal.Model.ElementSummary.get_ElementHistory()



Replies:
Posted By: kimj
Date Posted: 17-Oct-2010 at 1:29pm
I have good news and bad news.  The good news is that the problem, when the dependent data is present, was fixed in v6.0.6, which is coming soon.  The bad news is that the problem still exists if there is no dependent data.  We're looking into holding the 6.0.6 release a bit to get this fix in, but I won't know more until Monday. 


Posted By: jsobell
Date Posted: 17-Oct-2010 at 7:26pm
Yes, look back one post and you'll see exactly the same bug discussed :)
I did a short-term-workaround (complete bodge) for one client of making this a 1-* relationship in the database (I had to change the PK to an identity column in the second table), then adding a property to my Entity called TargetSingle that returned something like "return (Targets.Count > 0) ? Targets[0] : null;".
It's messy, but will work as a place-holder until the bug is fixed.

Cheers,
 Jason


Posted By: HunterMayer
Date Posted: 18-Oct-2010 at 10:15am
Jason, I see the merit of that workaround (bodge or not), thanks for the suggestion. I wish I had control of the database on this one. Worst case I think if I just lose them in the model we can run. But nothing I have thought up is as elegant as using a navigation property... I have hope the folks will fix it shortly. ;)
 
@kimj Thanks for the update!
 
I wonder if I make some animal sacrifices to the database priesthood in my shop they will allow a little modification for the time being...


Posted By: kimj
Date Posted: 19-Oct-2010 at 6:16pm
The problem should be fixed in v6.0.6, available now.



Print Page | Close Window