locked
Attach an entity whether its already attached or not RRS feed

  • Question

  • Hi

    I put this little extension into my Entities class (inheriting from DataServiceContext) in order to be able to ensure an entity was attached to the context without worrying about whether it might have already been attached:

                try
                {
                    this.AttachTo(entitySetName, entity);
                }
                catch
                { }

    Seems kinda obvious, but I found a bit of code was running really slowly and tracked it down to this.  I found that (presumably when the entity is already in the entity set and an exception is thrown internally) it takes about 10 MILLISECONDS to run.

    So does anyone know how to determine whether a context is already tracking an object, or why on earth this is so slow?

    Thanks

    James
    Wednesday, March 18, 2009 11:01 AM

Answers