// ReSharper disable DoNotCallOverridableMethodsInConstructor ///<summary> /// Constructs a single Relationship ///</summary> ///<param name="relationshipName"></param> ///<param name="relatedObjectAssemblyName"></param> ///<param name="relatedObjectClassName"></param> ///<param name="relKeyDef"></param> ///<param name="keepReferenceToRelatedObject"></param> ///<param name="deleteParentAction"></param> ///<param name="insertParentAction"><see cref="InsertParentAction"/></param> ///<param name="relationshipType"></param> public SingleRelationshipDef(string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) : base( relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType) { OwningBOHasForeignKey = true; }
private void SetupDefaultValues() { _deleteAction = DeleteParentAction.DoNothing; _insertAction = InsertParentAction.InsertRelationship; _relationshipType = RelationshipType.Association; _keepReference = true; _orderBy = ""; Type type = typeof(TRelatedType); _relatedObjectAssemblyName = type.Namespace; _relatedClassName = type.Name; _relKeyDef = new RelKeyDef(); _timeOut = 0; }
public MultipleRelationshipDefBuilder <T, TRelatedType> WithInsertParentAction( InsertParentAction insertParentAction) { _insertAction = insertParentAction; return(this); }
/// <summary> /// Loads the relationship definition from the reader. This method /// is called by LoadFromReader(). /// </summary> protected void LoadRelationshipDef() { _relatedClassName = _reader.GetAttribute("relatedClass"); _relatedAssemblyName = _reader.GetAttribute("relatedAssembly"); _name = _reader.GetAttribute("name"); _type = _reader.GetAttribute("type"); _preventDeleteMessage = _reader.GetAttribute("preventDeleteMessage"); string relationshipTypeString = _reader.GetAttribute("relationshipType"); try { _relationshipType = (RelationshipType) Enum.Parse(typeof (RelationshipType), relationshipTypeString); } catch (Exception ex) { throw new InvalidXmlDefinitionException (String.Format ("In the definition for the relationship '{0}' on class '{1}' " + "the 'relationshipType' " + "was set to an invalid value ('{2}'). The valid options are " + "Association, Aggregation and Composition.", _name, _className, relationshipTypeString), ex); } if (_type == null || (_type != "single" && _type != "multiple")) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'type' attribute was not included or was given " + "an invalid value. The 'type' refers to the type of " + "relationship and can be either 'single' or 'multiple'."); } _keepReferenceToRelatedObject = _reader.GetAttribute("keepReference") == "true"; _owningBOHasForeignKey = _reader.GetAttribute("owningBOHasForeignKey") == "true"; _reverseRelationshipName = _reader.GetAttribute("reverseRelationship"); _typeParameter = _reader.GetAttribute("typeParameter"); try { _timeout = Convert.ToInt32(_reader.GetAttribute("timeout")); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' element, " + "the 'timeout' attribute has been given " + "an invalid integer value.", ex); } _orderBy = _reader.GetAttribute("orderBy"); try { _deleteParentAction = (DeleteParentAction) Enum.Parse(typeof (DeleteParentAction), _reader.GetAttribute("deleteAction")); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given " + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and " + "Prevent.", ex); } if (_relationshipType == RelationshipType.Association) { try { string attribute = _reader.GetAttribute("insertAction"); if (string.IsNullOrEmpty(attribute)) { attribute = "InsertRelationship"; } _insertParentAction = (InsertParentAction) Enum.Parse(typeof (InsertParentAction), attribute); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given " + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and " + "Prevent.", ex); } } else { _insertParentAction = InsertParentAction.InsertRelationship; } }
/// <summary> /// Constructor to create a new single relationship definition /// </summary> /// <param name="relationshipName">A name for the relationship</param> /// <param name="relatedObjectAssemblyName">The assembly name of the related object</param> /// <param name="relatedObjectClassName">The class name of the related object</param> /// <param name="relKeyDef">The related key definition</param> /// <param name="keepReferenceToRelatedObject">Whether to keep a /// reference to the related object. Could be false for memory- /// intensive applications.</param> /// <param name="orderBy">The sql order-by clause</param> /// <param name="deleteParentAction">Provides specific instructions /// with regards to deleting a parent object. See the DeleteParentAction /// enumeration for more detail.</param> /// <param name="insertParentAction"></param> /// <param name="relationshipType">Provides specific instructions for adding/removing a child object.</param> /// <param name="timeout">The timout in milliseconds. The collection will not be automatically refreshed from the DB if the timeout has nto expired</param> public MultipleRelationshipDef(string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, string orderBy, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType, int timeout) : base(relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType) { ArgumentValidationHelper.CheckArgumentNotNull(orderBy, "orderBy"); TimeOut = timeout; OrderCriteriaString = orderBy; OrderCriteria = new OrderCriteria(); OrderCriteria = Base.OrderCriteria.FromString(orderBy); }
/// <summary> /// Loads the relationship definition from the reader. This method /// is called by LoadFromReader(). /// </summary> protected void LoadRelationshipDef() { _relatedClassName = _reader.GetAttribute("relatedClass"); _relatedAssemblyName = _reader.GetAttribute("relatedAssembly"); _name = _reader.GetAttribute("name"); _type = _reader.GetAttribute("type"); _preventDeleteMessage = _reader.GetAttribute("preventDeleteMessage"); string relationshipTypeString = _reader.GetAttribute("relationshipType"); try { _relationshipType = (RelationshipType)Enum.Parse(typeof(RelationshipType), relationshipTypeString); } catch (Exception ex) { throw new InvalidXmlDefinitionException (String.Format ("In the definition for the relationship '{0}' on class '{1}' " + "the 'relationshipType' " + "was set to an invalid value ('{2}'). The valid options are " + "Association, Aggregation and Composition.", _name, _className, relationshipTypeString), ex); } if (_type == null || (_type != "single" && _type != "multiple")) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'type' attribute was not included or was given " + "an invalid value. The 'type' refers to the type of " + "relationship and can be either 'single' or 'multiple'."); } _keepReferenceToRelatedObject = _reader.GetAttribute("keepReference") == "true"; _owningBOHasForeignKey = _reader.GetAttribute("owningBOHasForeignKey") == "true"; _reverseRelationshipName = _reader.GetAttribute("reverseRelationship"); _typeParameter = _reader.GetAttribute("typeParameter"); try { _timeout = Convert.ToInt32(_reader.GetAttribute("timeout")); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' element, " + "the 'timeout' attribute has been given " + "an invalid integer value.", ex); } _orderBy = _reader.GetAttribute("orderBy"); try { _deleteParentAction = (DeleteParentAction)Enum.Parse(typeof(DeleteParentAction), _reader.GetAttribute("deleteAction")); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given " + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and " + "Prevent.", ex); } if (_relationshipType == RelationshipType.Association) { try { string attribute = _reader.GetAttribute("insertAction"); if (string.IsNullOrEmpty(attribute)) { attribute = "InsertRelationship"; } _insertParentAction = (InsertParentAction) Enum.Parse(typeof(InsertParentAction), attribute); } catch (Exception ex) { throw new InvalidXmlDefinitionException ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given " + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and " + "Prevent.", ex); } } else { _insertParentAction = InsertParentAction.InsertRelationship; } }
// ReSharper disable DoNotCallOverridableMethodsInConstructor private RelationshipDef(string relationshipName, Type relatedObjectClassType, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) { ArgumentValidationHelper.CheckArgumentNotNull(relKeyDef, "relKeyDef"); ArgumentValidationHelper.CheckStringArgumentNotEmpty(relationshipName, "relationshipName"); if (relatedObjectClassType != null) MyRelatedObjectClassType = relatedObjectClassType; else { _relatedObjectAssemblyName = relatedObjectAssemblyName; _relatedObjectClassName = relatedObjectClassName; _relatedObjectClassType = null; } RelKeyDef = relKeyDef; RelationshipName = relationshipName; KeepReferenceToRelatedObject = keepReferenceToRelatedObject; this.DeleteParentAction = deleteParentAction; this.InsertParentAction = insertParentAction; RelationshipType = relationshipType; }
/// <summary> /// Constructor to create a new relationship definition /// </summary> /// <param name="relationshipName">A name for the relationship</param> /// <param name="relatedObjectAssemblyName">The assembly that the related object is in</param> /// <param name="relatedObjectClassName">The class type of the related object</param> /// <param name="relKeyDef">The related key definition</param> ///<param name="keepReferenceToRelatedObject">Whether to keep a /// reference to the related object. Could be false for memory- /// intensive applications.</param> ///<param name="deleteParentAction">The required action when the parent is deleted e.g. Dereference related, delete related, prevent delete</param> /// <param name="insertParentAction"><see cref="InsertParentAction"/></param> /// <param name="relationshipType"></param> protected RelationshipDef(string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) : this(relationshipName, null, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType) { }
// ReSharper disable DoNotCallOverridableMethodsInConstructor private RelationshipDef(string relationshipName, Type relatedObjectClassType, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) { ArgumentValidationHelper.CheckArgumentNotNull(relKeyDef, "relKeyDef"); ArgumentValidationHelper.CheckStringArgumentNotEmpty(relationshipName, "relationshipName"); if (relatedObjectClassType != null) { MyRelatedObjectClassType = relatedObjectClassType; } else { _relatedObjectAssemblyName = relatedObjectAssemblyName; _relatedObjectClassName = relatedObjectClassName; _relatedObjectClassType = null; } RelKeyDef = relKeyDef; RelationshipName = relationshipName; KeepReferenceToRelatedObject = keepReferenceToRelatedObject; this.DeleteParentAction = deleteParentAction; this.InsertParentAction = insertParentAction; RelationshipType = relationshipType; }
///<summary> ///</summary> ///<param name="relationshipName"></param> ///<param name="relatedAssemblyName"></param> ///<param name="relatedClassName"></param> ///<param name="relKeyDef"></param> ///<param name="keepReferenceToRelatedObject"></param> ///<param name="orderBy"></param> ///<param name="deleteParentAction"></param> ///<param name="insertParentAction"><see cref="InsertParentAction"/></param> ///<param name="relationshipType"></param> ///<param name="timeout">The timout in milliseconds. The collection will not be automatically refreshed from the DB if the timeout has not expired</param> ///<returns></returns> public IRelationshipDef CreateMultipleRelationshipDef (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, string orderBy, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType, int timeout) { return new MultipleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef, keepReferenceToRelatedObject, orderBy, deleteParentAction, insertParentAction, relationshipType, timeout); }
///<summary> ///</summary> ///<param name="relationshipName"></param> ///<param name="relatedAssemblyName"></param> ///<param name="relatedClassName"></param> ///<param name="relKeyDef"></param> ///<param name="keepReferenceToRelatedObject"></param> ///<param name="deleteParentAction"></param> ///<param name="insertParentAction"><see cref="InsertParentAction"/></param> ///<param name="relationshipType"></param> ///<returns></returns> public IRelationshipDef CreateSingleRelationshipDef (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) { return new SingleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType); }
///<summary> ///</summary> ///<param name="relationshipName"></param> ///<param name="relatedAssemblyName"></param> ///<param name="relatedClassName"></param> ///<param name="relKeyDef"></param> ///<param name="keepReferenceToRelatedObject"></param> ///<param name="orderBy"></param> ///<param name="deleteParentAction"></param> ///<param name="insertParentAction"><see cref="InsertParentAction"/></param> ///<param name="relationshipType"></param> ///<param name="timeout">The timout in milliseconds. The collection will not be automatically refreshed from the DB if the timeout has not expired</param> ///<returns></returns> public IRelationshipDef CreateMultipleRelationshipDef (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, string orderBy, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType, int timeout) { return (new MultipleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef, keepReferenceToRelatedObject, orderBy, deleteParentAction, insertParentAction, relationshipType, timeout)); }
///<summary> ///</summary> ///<param name="relationshipName"></param> ///<param name="relatedAssemblyName"></param> ///<param name="relatedClassName"></param> ///<param name="relKeyDef"></param> ///<param name="keepReferenceToRelatedObject"></param> ///<param name="deleteParentAction"></param> ///<param name="insertParentAction"><see cref="InsertParentAction"/></param> ///<param name="relationshipType"></param> ///<returns></returns> public IRelationshipDef CreateSingleRelationshipDef (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType) { return (new SingleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType)); }