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

[Solved] Delete not working

1 Answer 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nidhi Bhargava
Top achievements
Rank 1
Nidhi Bhargava asked on 01 Sep 2010, 08:37 AM
Hi ,


I am using this code in my application  :


Telerik.OpenAccess.ObjectContainer container = (Telerik.OpenAccess.ObjectContainer)Session["container"];

                try
                {
                    
                    container.Transaction.Begin();
                    List<EsfImage> data = container.NamedList("Images").Cast<EsfImage>().ToList();
                    EsfImage img = data.Where(x => x.ImageID == imageID && x.ImageSizeID == imageSizeID && x.SourceTypeID == sourceTypeID && x.ImageTypeID==imageTypeID).SingleOrDefault();
                    container.Remove(img);
                    container.NamedList("Images").Remove(img);
                    container.Transaction.Commit();
                  
                }

When this code execute it shows that row is deleted but when i refresh page then i can see that row again,please help where i am doing wrong

1 Answer, 1 is accepted

Sort by
0
Petko_I
Telerik team
answered on 07 Sep 2010, 09:01 AM
Hi Nidhi Bhargava,

Sorry for the delayed answer – it really isn’t our practice to be unresponsive.
I see that you have concentrated your attention on using the ObjectContainer. When you remove an object from the container, the object’s state is set to DELETED. Subsequent querying for this object with the container, however, successfully retrieves it. In order to filter the deleted objects you can use the container’s method IsRemoved. Thus when you get a collection you should apply a filter condition such as this: !container.IsRemoved(persistentObject).

When you propagate the changes to the database after copying the object graph (i.e. container state) to an IObjectScope with the CopyTo method, you will no longer retrieve deleted objects:
IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); 
scope.Transaction.Begin(); 
container.CopyTo(scope, ObjectContainer.Verify.All); 
scope.Transaction.Commit(); 

In case you haven’t read our resources for the ObjectContainer usage, you can have a look at the blog posts:
Using Object Container to transport persistent objects between multiple pages.
Using the ObjectContainer in disconnected scenarios
Using the ObjectContainer in disconnected scenarios – Part 2

I hope the IsRemoved method is what you are looking for. Do not hesitate to contact us if you have more questions or I have misunderstood your problem.

Best wishes,

Petko_I
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
General Discussions
Asked by
Nidhi Bhargava
Top achievements
Rank 1
Answers by
Petko_I
Telerik team
Share this question
or