how to delete an row in database?
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1181
Printed Date: 22-Sep-2025 at 2:53pm
Topic: how to delete an row in database?
Posted By: monkeyking
Subject: how to delete an row in database?
Date 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
|
Replies:
Posted By: jeffdoolittle
Date 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
|
Posted By: monkeyking
Date 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.
|
Posted By: jeffdoolittle
Date 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
|
Posted By: monkeyking
Date 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?
|
Posted By: davidklitzke
Date 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.
|
Posted By: monkeyking
Date Posted: 07-Apr-2009 at 6:55pm
thx David, how can i refer to other table with a devforce entity?
|
Posted By: davidklitzke
Date 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.
|
Posted By: rclarke
Date 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.
|
|