public bool IsFieldDirty(string fieldName) { Schema.Field field = GetField(fieldName); object currentValue = field.GetValue(this); object dirtyValue = GetDirtyValue(fieldName); if (currentValue == null && dirtyValue == null) { return(false); } return(currentValue == null ? !dirtyValue.Equals(currentValue) : !currentValue.Equals(dirtyValue)); }
protected virtual List <FKConstraintConflict> GetFKConstraintConflicts(ITransaction transaction) { List <FKConstraintConflict> fKConstraintConflicts = new List <FKConstraintConflict>(); SchemaObject mySchemaObject = Schema.Schema.GetSchemaObject(GetType()); Schema.Field primaryKeyField = mySchemaObject.PrimaryKeyField; foreach (RelationshipList relationshipList in Schema.Schema.GetSchemaObject(GetType()).GetRelationshipLists()) { SchemaObject relatedSchemaObject = Schema.Schema.GetSchemaObject(relationshipList.RelatedObjectType); Schema.Field relatedField = relatedSchemaObject.GetField(relationshipList.ForeignKeyName); ISelectQuery relationshipListQuery = SQLProviderFactory.GetSelectQuery(); relationshipListQuery.SelectList.Add(relatedSchemaObject.PrimaryKeyField.FieldName); relationshipListQuery.Table = new Table(relatedSchemaObject.SchemaName, relatedSchemaObject.ObjectName); relationshipListQuery.WhereCondition = new Condition() { Left = (Base.Data.Operand.Field)relatedField.FieldName, ConditionType = Condition.ConditionTypes.Equal, Right = new Literal(primaryKeyField.GetValue(this)) }; DataTable results = relationshipListQuery.Execute(transaction); foreach (DataRow row in results.Rows) { FKConstraintConflict fKConstraintConflict = new FKConstraintConflict(); fKConstraintConflict.ConflictType = relationshipList.RelatedObjectType; fKConstraintConflict.ForeignKey = row[relatedSchemaObject.PrimaryKeyField.FieldName] as long?; fKConstraintConflict.ForeignKeyName = relatedField.FieldName; fKConstraintConflict.ActionType = relationshipList.AutoDeleteReferences ? FKConstraintConflict.ActionTypes.AutoDeleteReference : relationshipList.AutoRemoveReferences ? FKConstraintConflict.ActionTypes.AutoRemoveReference : FKConstraintConflict.ActionTypes.Conflict; fKConstraintConflicts.Add(fKConstraintConflict); } } return(fKConstraintConflicts); }