I have a Dynamics CRM Plugin registered in "Pre Validation" and trigger on delete. I have inside it a LINQ query that retrieve the maximum value of a date field of children records for a particular parent record.
Here is my code:
var q = (from e1 in serviceContext.CreateQuery<entity1>()
join e2 in serviceContext.CreateQuery<entity2>() on e1.typeid.Id equals e2.codeId
where e1.statecode == 0 && e1.ParentId.Id.Equals(new Guid(ParentGuidStr))
orderby e1.dt descending
select new {e1.dt, e2.code}).ToList();
I am getting the following error on the above query When the record that the plugin triggers on is INACTIVE:
PreValidateEntity1Delete PlugIn Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null. Parameter name: g
I am NOT sure why I am getting the above error and if the link between an inactive children record and a parent record got broken in a LINQ query or there is another reason.