3

Am a little lost on this one. Getting the error Object reference not set to an instance of an object. on the line db.EntityRichContents.DeleteAllOnSubmit(q); at runtime. Project builds fine.

protected override void ControllerOnEntityDeleted(EntityObj forEntity, EntityDeletionController.DeletionAction newStatus)
{
    if (newStatus == EntityDeletionController.DeletionAction.HardDelete)
    {
        if(forEntity == null) throw new Exception();

        using (var db = new DBContext())
        {
            var q = db.EntityRichContents.Where(c => c.C3Entity == ForEntity.TypeID && c.C3EntityRecordID == ForEntity.ID);
            db.EntityRichContents.DeleteAllOnSubmit(q);
            db.SubmitChanges();
        }
    }
}

Checking q.Any() or q == null doesn't help in any way (q isn't null).

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456

1 Answers1

1

I see there are two similar variables: one is ForEntity (possibly a class property property?) and the second being forEntity (method parameter). Is that a typo?

Either way, given that the Where method is enumerated lazily I would assume that one of the lambda parameters in (c => c.C3Entity == ForEntity.TypeID && c.C3EntityRecordID == ForEntity.ID) is null. Try adding null-checks for every parameter and/or property to avoid exceptions.

zen
  • 353
  • 2
  • 12