The EntitySet is already loaded and the source cannot be

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
andrewjco
Posts: 3
Joined: Wed 20 May 2009 01:39

The EntitySet is already loaded and the source cannot be

Post by andrewjco » Wed 22 Jul 2009 02:16

Hi,

I get an exception when trying to re-attach entities to a context.

"The EntitySet is already loaded and the source cannot be changed."

I'm trying to figure out under what circumstances this message will be fired?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 22 Jul 2009 11:26

Could you please post the code you are using to re-attach an entity?

andrewjco
Posts: 3
Joined: Wed 20 May 2009 01:39

Post by andrewjco » Thu 23 Jul 2009 03:51

Not easily unfortunately, although I could try and whip up a sample project.

There seems to be very little info on google for this error, so I was more interested if you guys could tell me why it might fire.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 24 Jul 2009 10:48

Could you please post the call stack of the error here?
It should clarify the problem.
Incorrect SetSource method usage could also be a reason if this problem.

Nahmis
Posts: 30
Joined: Mon 13 Jul 2009 21:38

Call Stack

Post by Nahmis » Sat 19 Sep 2009 13:42

We're also seeing this behavior since latest release, here's the callstack that blows up after a call to:

Code: Select all

DataContext.GetTable().Attach(OurUpdatedObjectFromTheSameContext, true);

Code: Select all

[InvalidOperationException: The EntitySet is already loaded and the source cannot be changed.]
   System.Data.Linq.EntitySet`1.SetSource(IEnumerable`1 entitySource) +807755
   Devart.Data.Linq.Mapping.EntitySetDefSourceAccessor`2.a(T& A_0, IEnumerable`1 A_1) +104
   System.Data.Linq.Mapping.MetaAccessor`2.SetBoxedValue(Object& instance, Object value) +84
   Devart.Data.Linq.Provider.d.SetLinks(TEntity obj, Object keySource, IList`1 linkMembers, EntityCache`2 cache, f services, IList`1 queryLoadWith, Dictionary`2 nextLoadWiths) +1154

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +261
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
   Devart.Data.Linq.Table`1.a(TEntity A_0, TEntity A_1, Boolean A_2) +691
   Devart.Data.Linq.Table`1.Attach(TEntity entity, Boolean asModified) +13

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 21 Sep 2009 14:26

Thank you for the report, we are investigating the problem.
I will let you know about the results.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 06 Oct 2009 13:16

We have fixed the problem. Look forward to the next build.

Post Reply