/// <summary> /// Returns whether or not that field's value is currently null/nothing /// </summary> /// <param name="fieldName">Field name as it appears in the data set</param> /// <param name="mode">Link table or target table?</param> /// <returns>True or false</returns> public virtual bool IsFieldNull(string fieldName, XLinkItemAccessMode mode) { if (mode == XLinkItemAccessMode.CurrentTable) { return(IsFieldNull(fieldName)); } if (ParentEntity is BusinessEntity entity) { fieldName = entity.GetInternalFieldName(fieldName, currentTargetRow.Table.TableName); } return(currentTargetRow[fieldName] == DBNull.Value); }
/// <summary> /// Returns the value of the specified field in the database /// </summary> /// <typeparam name="TField">The type of the field.</typeparam> /// <param name="fieldName">Field name</param> /// <param name="mode">Accessing a field in the parent (link) or target (child/foreign) table?</param> /// <param name="ignoreNulls"> /// Should nulls be ignored and returned as such (true) or should the be turned into default /// values (false)? /// </param> /// <returns>Value object</returns> protected virtual TField ReadFieldValue <TField>(string fieldName, XLinkItemAccessMode mode, bool ignoreNulls = false) { if (mode == XLinkItemAccessMode.CurrentTable) { return(ReadFieldValue <TField>(fieldName)); } if (!(ParentEntity is BusinessEntity entity)) { throw new NullReferenceException("Parent entity is not a business entity."); } return(BusinessEntityHelper.GetFieldValue <TField>(entity, CurrentTargetRow.Table.DataSet, CurrentTargetRow.Table.TableName, fieldName, CurrentTargetRow, ignoreNulls)); }
/// <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> /// <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 SetFieldValue(string fieldName, object 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> /// Returns the value of the specified field in the database /// </summary> /// <param name="fieldName">Field name</param> /// <param name="mode">Accessing a field in the parent (link) or target (child/foreign) table?</param> /// <param name="ignoreNulls"> /// Should nulls be ignored and returned as such (true) or should the be turned into default /// values (false)? /// </param> /// <returns>Value object</returns> protected virtual object GetFieldValue(string fieldName, XLinkItemAccessMode mode, bool ignoreNulls = false) { if (mode == XLinkItemAccessMode.CurrentTable) { return(GetFieldValue(fieldName)); } var entity = ParentEntity as BusinessEntity; if (entity == null) { throw new NullReferenceException("Parent entity is not a business entity."); } return(BusinessEntityHelper.GetFieldValue <object>(entity, CurrentTargetRow.Table.DataSet, CurrentTargetRow.Table.TableName, fieldName, CurrentTargetRow, ignoreNulls)); }