/// <summary>Sets the value of a field in the database. This overload allows to specify whether the value is set in the master table, or the target table.</summary> /// <typeparam name="TField">The type of the field.</typeparam> /// <param name="fieldName">Field name</param> /// <param name="value">New value</param> /// <param name="mode">Specifies whether we want to access the current (link) table ("Current") or the target table.</param> /// <param name="forceUpdate"> /// Should the value be set, even if it is the same as before (and therefore set the dirty flag /// despite that there were no changes)? /// </param> /// <returns>True or False</returns> protected virtual bool WriteFieldValue <TField>(string fieldName, TField value, XLinkItemAccessMode mode, bool forceUpdate = false) { if (mode == XLinkItemAccessMode.CurrentTable) { return(SetFieldValue(fieldName, value, forceUpdate)); } BusinessEntityHelper.CheckColumn(CurrentTargetRow.Table, fieldName); if (!(ParentEntity is BusinessEntity entity)) { throw new NullReferenceException("Parent entity is not a business entity."); } return(BusinessEntityHelper.SetFieldValue(entity, fieldName, value, CurrentTargetRow.Table.TableName, CurrentRow.Table.DataSet, CurrentTargetRow, forceUpdate)); }
/// <summary> /// This method can be used to make sure the default table in the internal DataSet has all the required fields. /// If the field (column) doesn't exist, it will be added. /// </summary> /// <param name="fieldName">Field name to check for.</param> /// <param name="tableToCheck">Table that is supposed to have this column.</param> /// <returns>true or false</returns> protected virtual bool CheckColumn(string fieldName, DataTable tableToCheck) => BusinessEntityHelper.CheckColumn(tableToCheck, fieldName);
/// <summary> /// Method used to check whether the current data row has a certain field /// This overload allows passing a table object. /// </summary> /// <param name="fieldName">Field Name</param> /// <param name="tableRow">DataRow the field is a member of</param> /// <returns>True (if the column existed or has been added successfully) or False</returns> protected virtual bool CheckColumn(string fieldName, DataRow tableRow) => BusinessEntityHelper.CheckColumn(tableRow.Table, fieldName);