Everything looks good with your QueryExpression
, although I'd write it a little more concise (something like this):
var qe = new QueryExpression(SharePointDocumentLocation.EntityLogicalName){
ColmnSet = new ColumnSet("sharepointdocumentlocationid"),
};
qe.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, id);
Because I don't see anything wrong with the QueryExpression
that leads me with two guesses.
You're using impersonation on the
IOrganizationService
and the impersonated user doesn't have rights to theSharePointDocumentLocation
. You won't get an error, you just won't get any records returned.The id you're passing in is incorrect.
I'd remove the Criteria
and see how many records you get back. If you don't get all of the records back, you know your issue is with guess #1.
If you get all records, add the regardingobjectid
to the ColumnSet
and retrieve the first record without any Criteria
in the QueryExpression
, then call this method passing in the id of the regardingobject
you returned. If nothing is received when adding the regardingobjectid
constraint, then something else is wrong.
Update
Since this is executing within the delete of the plugin, it must be performing its cascade deletes before your plugin is firing. You can try the Pre-Validation.
Now that I think of it, it must perform the deletion of the cascading entities in the Validation stage, because if one of them is unable to be deleted, the entity itself can't be deleted.