Tested on Versions 4.4.2 -> 4.5.3_RC

Code Example 1 (PersonCategory is already an item in PersonCategories EntitySet):

  • Person.PersonCategories.Clear(); (same with Remove)
  • Person.PersonCategories.Add( PersonCategory );

System.InvalidOperationException: Message = "State with key 'Person-PersonCategories-PersonCategory, (957, 921)' is already exists."

StackTrace:

  • at Xtensive.Orm.Disconnected.StateRegistry.Create(Key key, Tuple tuple, Boolean isLoaded)
  • at Xtensive.Orm.DisconnectedState.Persist(EntityState entityState, PersistActionKind persistAction)
  • at Xtensive.Orm.Disconnected.DisconnectedSessionHandler.<persist>b__0(EntityState item)
  • at Xtensive.Core.EnumerableExtensions.ForEachT
  • at Xtensive.Orm.Disconnected.DisconnectedSessionHandler.Persist(EntityChangeRegistry registry, Boolean allowPartialExecution)
  • at Xtensive.Orm.Session.Persist(PersistReason reason)
  • at Xtensive.Orm.Session.CommitTransaction(Transaction transaction)
  • at Xtensive.Orm.Transaction.Commit()
  • at Xtensive.Orm.TransactionScope.Dispose()
  • at Xtensive.Core.DisposableExtensions.DisposeSafely(IDisposable disposable)
  • at Xtensive.Orm.TransactionalAttribute.OnExit(MethodExecutionArgs args)
  • at Xtensive.Orm.EntitySetBase.Add(Entity item)
  • at Xtensive.Orm.EntitySetBase.Add(IEntity item)
  • at Xtensive.Orm.EntitySet`1.Add(TItem item)

Code Example 2 (No item in PersonCategories EntitySet):

  • Person.PersonCategories.Add( PersonCategory );
  • Person.PersonCategories.Clear();
  • Person.PersonCategories.Add( PersonCategory );
  • Person.PersonCategories.Clear();

System.NullReferenceException: Message = "Object reference not set to an instance of an object."

StackTrace:

  • at Xtensive.Orm.Session.RemoveOrCreateRemovedEntity(Type type, Key key)
  • at Xtensive.Orm.EntitySetBase.<>cDisplayClass10.<remove>b9()
  • at Xtensive.Orm.EntitySetBase.Remove(Entity item, SyncContext syncContext, RemovalContext removalContext)
  • at Xtensive.Orm.EntitySetBase.Remove(Entity item)
  • at Xtensive.Orm.EntitySetBase.Remove(IEntity item)
  • at Xtensive.Orm.EntitySetBase.Clear()

asked Jun 03 '12 at 11:00

TeaMan's gravatar image

TeaMan
140141418

I can confirm these issues with released version, our current 4.5.x branch contains some improvements for client profile, and your examples work well with it.

(Jun 04 '12 at 09:15) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

It doesn't work with 4.5.3 RC. Is there a newer version?

(Jun 04 '12 at 09:45) TeaMan TeaMan's gravatar image

We've just uploaded it http://dataobjects.net/downloads/default.aspx#eap Please confirm if this works for you.

(Jun 04 '12 at 10:10) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

Thank you for your quick help. In initial tests, it seems to work.

Unfortunately is now another part broken. In Session.DisconnectedState.Operations there are no entries anymore. I used the Count Property, whether the call to SaveChanges() is necessary. Is there another way to identify changes in data before save?

(Jun 05 '12 at 05:19) TeaMan TeaMan's gravatar image

DO now fills operation log inside SaveChanges(). You should not rely on a particular behaviour unless your managing disconnected state manually.

For counting number of entities to save you can subscribe to Session.Events.EntityCreated, Session.Events.EntityRemoveCompleted and so on.

If you want to create large number of entities it's performance-wise to have a separate session using ServerProfile.

(Jun 05 '12 at 06:41) Denis Krjuchkov Denis%20Krjuchkov's gravatar image
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA