Print Page | Close Window

Deleting Record

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2073
Printed Date: 21-Oct-2025 at 2:55pm


Topic: Deleting Record
Posted By: bala
Subject: Deleting Record
Date Posted: 18-Aug-2010 at 12:46pm
Hi There
New in DevForce..
I am try to deleting record from Data Grid but Could not get sucess yet.

I have simple datagrid where i am displaying record... and Added 4 button for CRUD operation
but my delete is not working..
Below the sample code

STUDENT stud = Students.Where(t => t.ID == Convert.ToDecimal(_id)).Single();
           _mgr.RemoveEntity(stud);
           _mgr.SaveChangesAsync();


Any Help would be highly appriciated..

Thanks in Advance



Replies:
Posted By: smi-mark
Date Posted: 18-Aug-2010 at 2:25pm
You need to call stud.EntityAspect.Delete(); rather than _mgr.RemoveEntity


Posted By: bala
Date Posted: 19-Aug-2010 at 9:17am
I did
but Its not deleting records.. neither showing any exception or error..




Posted By: smi-mark
Date Posted: 19-Aug-2010 at 9:19am
STUDENT stud = Students.Where(t => t.ID == Convert.ToDecimal(_id)).Single();
stud.EntityAspect.Delete();
_mgr.SaveChangesAsync();

That should do everything you need... stud is not coming back as a null entity, correct?


Posted By: ting
Date Posted: 19-Aug-2010 at 6:00pm
Before you call Delete(), you should also remove it from the datasource for the grid.  Once delete is called, the entity will be in a detached state and should not have any operations performed on it.  As Mark points out, SaveChangesAsync() will then finally commit the delete to the database.


Posted By: bala
Date Posted: 20-Aug-2010 at 4:26am
Finally
work with this code..

STUDENT stud = Students.Where(t => t.ID == Convert.ToDecimal(_id)).Single();
                stud.EntityAspect.Delete();
                Students.Remove(stud);
                _mgr.SaveChangesAsync();



Print Page | Close Window