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:

                    this.AttachTo(entitySetName, entity);
                { }

    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?


    Wednesday, March 18, 2009 11:01 AM