Support Topics Documentation Slack YouTube Blog

Deleting one to one relationship .Net


(Maheed Hatem) #1

I have a Table called Group with a column “DefaultSubGroup” which is a one to one relationship to a table called SubGroup. I fail to set the relationship and clear it in the same session. Here are the steps that cause the problem.

1- DefaultSubGroup for MyGroup is initially null
2- Set DefaultSubGroup for MyGroup to a SubGroup “defaultSubGroup”.
3- Save MyGroup
4- Clear DefaultSubGroup for MyGroup by setting it to null
5- Save MyGroup
After these steps somehow DefaultSubGroup for MyGroup remains set to defaultSubGroup object and is not cleared. If i refetch MyGroup Object then clear DefaultSubGroup it works.
Code for setting DefaultSubGroup


 MyGroup.DefaultSubGroup = defaultSubGroup;
            AsyncCallback<Group> saveCallBack = new AsyncCallback<Group>(
                group =>
                {
                    //
                },
                fault =>
                {
                    //
                });
            Backendless.Data.Of<Group>().Save(MyGroup, saveCallBack);


Code for clearing the relationship


 MyGroup.DefaultSubGroup = null;
            AsyncCallback<Group> saveCallBack = new AsyncCallback<Group>(
                group =>
                {
                    //
                },
                fault =>
                {
                    //
                });
            Backendless.Data.Of<Group>().Save(MyGroup, saveCallBack);


Am I doing something wrong?


(Sergey Chupov) #2

Hi Maheed,In order to remove relation (set it to null), you need to first load it. So add a find call to your workflow and it should work fine.