Question

SQL Error when deleting

Hello,

Dear community; 

 

I've one question; I've a source code in my platform, where I coded a function that can delete Asset, this function is running well when nothing is linked to the Asset, 

For example if I link the heater type to one asset, the function doesn't work. 

I would quote that I run the function by postman, and there are few errors that I dont understand 

 

There is one message of an error : 

 

 

Here you can find my source code of my function : 

        public string DeletingAsset(string idAsset)
        {
            var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];
            var delete = new Delete(userConnection)
                .From("yooAsset")
                 .Where("Id").IsEqual(Column.Const(idAsset));
            var cnt = delete.Execute();
               return $"Asset with idAsset {idAsset} were deleted. {cnt} rows affected";
        }

Like

4 comments

Hello Rocher,

It is base SQL message that the record you are trying to delete is used as a value of yooAssetId column of yooHouseProtectionInAsset table. To resolve this error simply firstly update yooAssetId column of yooHouseProtectionInAsset table record value to NULL where yooAssetId column value is equal to the value you are trying to delete. Or modify your logic so that all records from yooHouseProtectionInAsset  table that refer to the value you are trying to delete (via column yooAssetId) could be automatically deleted when you delete the value when using:

public string DeletingAsset(string idAsset)
        {
            var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];
            var delete = new Delete(userConnection)
                .From("yooAsset")
                 .Where("Id").IsEqual(Column.Const(idAsset));
            var cnt = delete.Execute();
               return $"Asset with idAsset {idAsset} were deleted. {cnt} rows affected";
        }

Best regards,

Oscar

Oscar Dylan,

Maybe I dont explain my problem well, the Asset will be always connected to several detail, I want to know how can I delete this Asset properly just this Asset and not the records which are linked to

Rocher,

Then you simply need to update yooAssetId column value to NULL for the record in yooHouseProtectionInAsset table where yooAssetId = 'value you are trying to remove'. As a result main record you are trying to delete will be deleted and at the same time nothing will be deleted from 

yooHouseProtectionInAsset table.

Best regards,

Oscar

Oscar Dylan,

That's not my question.. 

I want to delete the data in the table yooAsset, and the data in the all related table. So I'm asking is there parameters for deletion request that permit cascading deletion ?

Log in or register to comment