SharePoint: Set delete behavior on a Lookup Field

SPFieldLookup class includes a RelationshipDeleteBehavior property that enables you to specify the delete behavior for the column.

  • SPRelationshipDeleteBehavior.Cascade
  • SPRelationshipDeleteBehavior.Restrict


private void RestrictDeleteOnLookupField(SPWeb web, string listUrl, Guid fieldGuid)
{
SPList list = web.GetList(GetListUrl(web.ServerRelativeUrl, listUrl));
SPField field = list.Fields[fieldGuid];
SPFieldLookup fieldLookup = (SPFieldLookup)field;
fieldLookup.Indexed = true;
fieldLookup.RelationshipDeleteBehavior =
SPRelationshipDeleteBehavior.Restrict;
fieldLookup.Update();
}

Continue ReadingSharePoint: Set delete behavior on a Lookup Field