Page 1 of 1

Cannot save entity because it is not tracked by the context.

Posted: Tue 08 Aug 2017 21:28
by -marcelo-
Devart“s newbie here...
I made a partial class to complement the DataContext as generated by Entity developer (5.7.586) so I
can implement the partials Insert/Update/Delete, this way

Code: Select all

        partial void InsertSomeEntity(SomeEntity instance)
        {
            ExecuteDynamicInsert(instance);
        }

        public void InsertSomeEntity(SomeEntity instance, bool dummy )
        {
            InsertSomeEntity(instance);
        }
The last is to change the signature, so it can be public. But when I call this method with a new instance of SomeEntity, the library throws an exception saying "Cannot save the entity object 'SomeEntity' because it is not tracked by the context."

If the partial methods are there (in the code generated) as well as a collection of them ( public Devart.Data.Linq.Table<SomeEntity> SomeEntities) how is this that the entity is not tracked?
What am I doing the wrong way?
TIA

Re: Cannot save entity because it is not tracked by the context.

Posted: Wed 09 Aug 2017 13:51
by -marcelo-
I found my error: for insertion of a new entity I must go throug context.SomeEntities.InsertOnUpdate( instance ) and context.SubmitChanges();

Re: Cannot save entity because it is not tracked by the context.

Posted: Thu 10 Aug 2017 15:10
by Shalex
Thank you for confirming solution. As we understood, no investigation on our side is required.