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

Multiple field Identity / Cascade Delete

1 Answer 73 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
George
Top achievements
Rank 1
George asked on 10 Jun 2010, 04:23 PM
Hi Team,

I don't know if this is the right place for this post. I have a tiny problem with OpenAccess and I'll appreciate it if you can help me solve it. I am sure it is a simple trick.

So basically I am using Forward Mapping ... In my model I have a class called MediaLanguage having (int Id, IList<MediaLanguageLocalization> Localizations) and another class MediaLanguageLocalization(int Id, string cultureName, string Name, string Description)

I have implemented the multiple field identity for this architecture using the IObjectId and it worked perfectly. The only problem that I have left is in the Cascade Delete ... I have set the Cascade delete option for the Localizations property but still everytime I delete my MediaLanguage entity the relevant entries from the "bc_MdLngg_bc_MdLnggLcalization" table get deleted but the entries in the table mapped to MediaLanguageLocalization remain intact.. 

I am deleting the MediaLanguage entity using the following function: 
        public void Delete(int id) 
        { 
            var query = from item in Context.ObjectScope.Extent<MediaLanguage>() 
                        where item.Id == id 
                        select item; 
 
            if (query.Count() > 0) 
            { 
                var entity = query.Single(); 
 
                Context.ObjectScope.Remove(entity); 
            } 
        } 

If I query the MediaLanguage that I have let's say for the english language after the deletion ... The Items are still there ... So the question is how can I make the Cascade delete to work properly ...

Appreciate it in advance.

G




1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 14 Jun 2010, 10:02 AM
Hello G-force,
This is a little complicated because we do not know about all your languages. The best way to do it by yourself, is to implement the IInstanceCallbacks interface at your persistent class. In the PreDelete you can delete all dependent data.

To get the scope inside the persistent objects please call Database.GetContext(this).

Best wishes,
Jan Blessenohl
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
Development (API, general questions)
Asked by
George
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Share this question
or