New Posts New Posts RSS Feed: Deleting Record
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleting Record

 Post Reply Post Reply
Author
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post Topic: Deleting Record
    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();
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post Posted: 19-Aug-2010 at 9:17am
I did
but Its not deleting records.. neither showing any exception or error..


Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 18-Aug-2010 at 2:25pm
You need to call stud.EntityAspect.Delete(); rather than _mgr.RemoveEntity
Back to Top
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down