This is a migrated thread and some comments may be shown as answers.

delete an entity without actually load it into the context

5 Answers 70 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AndreaT
Top achievements
Rank 1
AndreaT asked on 27 Oct 2010, 10:38 AM
Hi,

is there a method to execute e database delete without the need to load the object into the db context  before calling DbCtx.Delete(obj)? By now what I do is:

1) get the object key from a grid/list
2) query/load the object from the dbcontext
3) perform a context.Delete(obi)
4) perform a context.SaveChanges() to persist the delete

In web application is a day-by-day task to bind grids  to object lists and perform a delete operation querying the object key from the grid itself. performing steps 1->4. is a huge waste of resources (and processing time).

best regards
Andrea

5 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 29 Oct 2010, 07:05 PM
Hello AndreaT,

I am afraid that there is no other approach that you can use in this scenario. However, if the object has already been loaded in order to be shown in the grid, it is cached in the context instance used to retrieve it. So in most cases when you try to delete it, it will not be read again from the database but from the cache. Hope that helps.

Regards,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
AndreaT
Top achievements
Rank 1
answered on 31 Oct 2010, 09:59 AM
Hi,

unfortunately in a web application the context is wiped out at the end of the page life cycle. Performing delete preloading the object is a havy duty (and unnecessary) job. It would be better to have a direct method to perform deletions.

thank you

Andrea
0
Damyan Bogoev
Telerik team
answered on 02 Nov 2010, 08:34 PM
Hi AndreaT,

I think the only other solution you could use is to call a stored procedure which deletes the record from the database. Here are the steps you should follow:
1. Create a stored procedure on the sql server which can delete an object using its primary key;
2. Reverse map the stored procedure using the Update from Database wizard;
3. Execute the method which is mapped to the stored procedure:

...
context.StoredProcedureMethod(id);
...

Hope that helps.

Best wishes,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
IT-Als
Top achievements
Rank 1
answered on 03 Nov 2010, 01:34 PM
Hi AndreaT and Damyan,

Sorry for interfering your thread, but another solution could be to enable the L2 cache. Especially since (as per the scenario AndreaT described) a list of objects are loaded initially and thus they are already present in the L2 cache.

So, as the L2 cache lives next to the L1 cache in the Scope/Context and never dies when a Scope/Context dies it will be a nice solution I guess.

Since the object is already loaded during display in web app, fetching it for delete will not hit the database (but go to the L2 cache for the object) and thus it can be deleted afterwards.

Just my thoughts,

Regards

Henrik
0
Damyan Bogoev
Telerik team
answered on 05 Nov 2010, 09:23 PM
Hi Andrea,

Henrik is right, you can try the level 2 cache as well. Helpful information regarding the caching mechanisms in OpenAccess ORM can be found here, here and here. This help article demonstrates how to set the caching mechanism for your domain model.

Best wishes,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Getting Started
Asked by
AndreaT
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
AndreaT
Top achievements
Rank 1
IT-Als
Top achievements
Rank 1
Share this question
or