Author |
Share Topic Topic Search Topic Options
|
monkeyking
Groupie
Joined: 04-Mar-2009
Location: brisbane
Posts: 68
|
Post Options
Quote Reply
Topic: how to delete an row in database? 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
|
 |
jeffdoolittle
Senior Member
Joined: 14-Jun-2007
Location: United States
Posts: 146
|
Post Options
Quote Reply
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
|
 |
monkeyking
Groupie
Joined: 04-Mar-2009
Location: brisbane
Posts: 68
|
Post Options
Quote Reply
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.
|
 |
jeffdoolittle
Senior Member
Joined: 14-Jun-2007
Location: United States
Posts: 146
|
Post Options
Quote Reply
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
|
 |
monkeyking
Groupie
Joined: 04-Mar-2009
Location: brisbane
Posts: 68
|
Post Options
Quote Reply
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?
|
 |
davidklitzke
IdeaBlade
Joined: 14-Jun-2007
Posts: 715
|
Post Options
Quote Reply
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.
|
 |
monkeyking
Groupie
Joined: 04-Mar-2009
Location: brisbane
Posts: 68
|
Post Options
Quote Reply
Posted: 07-Apr-2009 at 6:55pm |
thx David, how can i refer to other table with a devforce entity?
|
 |
davidklitzke
IdeaBlade
Joined: 14-Jun-2007
Posts: 715
|
Post Options
Quote Reply
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.
|
 |
rclarke
Groupie
Joined: 14-Jun-2007
Location: United States
Posts: 69
|
Post Options
Quote Reply
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.
|
 |