public static bool IsMarkedAsParentContext(this FieldDef entityFieldDef) { if (entityFieldDef.DataType != DataType.Entity) { throw new ArgumentException("Field must be an entity field in order to mark as parent context"); } // Parent context is stored as an implicit cascade on the embedded entity // The parent of the cascade is the parent entity, the child of the cascade is the embedded entity // The field that contains the cascade is not stored if (entityFieldDef.Parent is EntityDef) { var parentEntityDef = (EntityDef)entityFieldDef.Parent; if (parentEntityDef == null) { throw new ArgumentException( "Field must be added to an entity before is can be marked as parent context"); } var childEntityDef = entityFieldDef.GetRuleApp().Entities[entityFieldDef.DataTypeEntityName]; if (childEntityDef == null) { throw new ArgumentException("Entity type '" + entityFieldDef.DataTypeEntityName + "' could not be found. In order to create a parent context relationship, the entity type of the field must be a valid entity name"); } return(childEntityDef.CascadedReferences.Any( r => r.IsImplicit && r.ParentId == parentEntityDef.Guid && r.ChildId == childEntityDef.Guid)); } return(false); }