Removed/Deleted entity still want to update

Posts   
 
    
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 27-Apr-2012 23:24:26   

Hi,

I have a grid which to user can modify an entity within a collection. If the user modifies an entity I don't save it until the user exits the screen. The user can also delete an entity and the delete happens right away.

If the user first modifies an entity and then deletes an entity the entity gets deleted. When the user exists the screen the program tries to save the entity collection and aborts because it tries to update a deleted enity.

Here I delete and Assignment:

            Dim catidx = GradeBookMain.GradeBookCourse.Category.IndexOf(_SelectedCategory)
            GradeBookMain.GradeBookCourse.Category(catidx).Assignment.Remove(Assignment)
            MedfordSchoolDistrict.GradeBook.MedfordCommon.DeleteEntity(Assignment)

This is where I update on exit of the screen:

        GbMgr.CourseManager.SaveEntity(GradeBookMain.GradeBookCourse)

Here is the trace:

exec sp_executesql N'UPDATE [GradeBook].[dbo].[Assignment] SET [CategoryId]=@CategoryId,[Sequence]=@Sequence WHERE ( [GradeBook].[dbo].[Assignment].[AssignmentId] = @AssignmentId1)',N'@CategoryId int,@Sequence smallint,@AssignmentId1 int',@CategoryId=NULL,@Sequence=12,@AssignmentId1=28282

Any help would be appreciated.

I'm on version 2.6

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Apr-2012 06:51:08   

Seems like some object is holding a reference for Assignment, maybe one of the entities in the whole graph. Then you are separating it from the category, that's why the update is setting the CategoryId to NULL. Can you reproduce it in a simple code block (without your GUI)? Maybe some controls in your GUI maintain the Assignment object bound to the graph.

David Elizondo | LLBLGen Support Team
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 01-May-2012 00:01:26   

So, when you Remove the Assignment from the Assignment collection it sets the CategoryId to Null. Why does it do that?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-May-2012 08:21:11   

Fishy wrote:

So, when you Remove the Assignment from the Assignment collection it sets the CategoryId to Null. Why does it do that?

Because the PK-FK Synchronization. Follow the debugger at your .Remove(assignment) line and you will see what exactly happens.

So, my guess, as I said is that that object is referenced by another collection, or somehow the entity ends again in your graph. Maybe is a control in your GUI, I don't know, that's why I asked whether you can reproduce it in a simple snippet.

David Elizondo | LLBLGen Support Team
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 01-May-2012 17:00:14   

Thanks for the explanation. Yes, your right about it being referenced somewhere else. I was able to fix my problem. Thanks for your help.