New Posts New Posts RSS Feed: how to delete an row in database?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

how to delete an row in database?

 Post Reply Post Reply
Author
rclarke View Drop Down
Groupie
Groupie


Joined: 14-Jun-2007
Location: United States
Posts: 69
Post Options Post Options   Quote rclarke Quote  Post ReplyReply Direct Link To This Post Topic: how to delete an row in database?
    Posted: 08-Apr-2009 at 12:21pm
If your are using SQL Server and you have control of the database design you might want to look into setting cascading deletes on the relationship definition in SQL Server. This way when you delete a row like an order item, SQL Server will delete the order details as well as the order item. This reduces the risk of orphaned rows but may not be the behavior you want in all cases.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 08-Apr-2009 at 11:28am
In most cases, you will just know how to access the other table.  If you know about Orders, you will just know about OrderDetails.  I am not trying to solve the general problem of deletion failing becauser of some unkown foreign key.
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 07-Apr-2009 at 6:55pm
thx David, how can i refer to other table with a devforce entity?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 06-Apr-2009 at 9:58pm
You are correct.  You cannot delete a row that has a relationship to another row.  For example, you cannot delete an Order that has a bunch of OrderDetails.  To delete the Order, delete all of the OrderDetails.  Then delete the Order.
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 05-Apr-2009 at 11:58pm
thx Jeff

that works :-) I have another problem, where is here.


it think because that row refer to other table, so i couldn't delete it. but i can delete it if that table doesn't contain any forein key. so my question is, how can i deal with this issue?



Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 01-Apr-2009 at 12:09pm
In DevForce Classic, you can call myEntity.Delete() directly on an Entity.  In DevForce EF, you call myEntity.EntityAspect.Delete().


--Jeff
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 31-Mar-2009 at 11:38pm
each entity doesn't have a delete method to destroy itself. I used EntityManager.RemoveEntity(Entity), but it didn't work. see the second last line of code in the picture.
Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 31-Mar-2009 at 10:09pm
Removing an entity simply detaches it from the entity manager, leaving no pending changes to submit to the database.  Instead, you need to call Delete on the entity itself and then save the changes in the entity manager that is managing that entity.

--Jeff
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 31-Mar-2009 at 7:47pm
can any one please tell which section of the developer guide can teach insert, delete, update the database? i have no problem with insert and update, but i can't delete the row from database after i insert it.

for example, i create a new row, assign values on it and insert it into the cache, save it. it works fine, database be able to be changed. but once i add a line of code "manager.loginUsers.EntityManager.RemoveEntyt(auser);" to delete that row, database doesn't have any changes.




am i on the right track to insert a row? and how can i delete a row? which section introduce these techniques

Regards
John
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down