private RowObjectAdapter Bind(Selector columnNames) { foreach (PropertyInfo propertyInfo in Reflex.GetColumnProperties(obj)) { ColumnAttribute attribute = Reflex.GetColumnAttribute(propertyInfo); if (attribute != null && this.Row.Table.Columns.Contains(attribute.ColumnNameSaved)) { DataField field = this.fields.Add(attribute.ColumnNameSaved, attribute.Type); ColumnAdapter column = new ColumnAdapter(field); this.Bind(column); column.Field.Identity = attribute.Identity; column.Field.Primary = attribute.Primary; if (attribute.Identity || attribute.Computed || !columnNames.Exists(attribute.ColumnNameSaved)) { column.Field.Saved = false; } else { column.Field.Saved = attribute.Saved; } } } //in case of ColumnAttribute not setup Identity and Primary Keys fields.UpdatePrimaryIdentity(obj.Primary, obj.Identity); return(this); }
/// <summary> /// Create Empty System.Data.DataTable from ColumnAttribute of DPO fields /// </summary> /// <param name="type"></param> /// <returns></returns> private static DataTable GetEmptyDataTable(Type type) { DataTable dt = new DataTable(); foreach (PropertyInfo propertyInfo in Reflex.GetColumnProperties(type)) { ColumnAttribute a = Reflex.GetColumnAttribute(propertyInfo); if (a == null) { continue; } Type ty = propertyInfo.PropertyType.InnullableType(); DataColumn column = new DataColumn(a.ColumnName, ty); column.AllowDBNull = a.Nullable; column.AutoIncrement = a.Identity; column.Caption = a.Caption; //may need complicated logic for differentg type if (ty == typeof(string)) { column.MaxLength = a.Length; } dt.Columns.Add(column); } return(dt); }
public static void FillInstance(object instance, DataRow dataRow, bool defaultValueUsed) { foreach (PropertyInfo propertyInfo in Reflex.GetColumnProperties(instance)) { FillField(instance, propertyInfo, dataRow, defaultValueUsed); } }
private bool insertIdentityOn = false; //used for re-create table data during SQL Server updating protected PersistentObject() { Type type = this.GetType(); TableAttribute[] attributes = GetAttributes <TableAttribute>(); if (attributes.Length > 0) { dataTableAttribute = attributes[0]; } else { dataTableAttribute = new TableAttribute(type.Name, Level.Application); } this.columnProperties = Reflex.GetColumnProperties(type); }
/// <summary> /// Collect property values and save to DataRow /// </summary> /// <param name="dataRow"></param> public virtual void UpdateRow(DataRow dataRow) { foreach (PropertyInfo propertyInfo in Reflex.GetColumnProperties(this)) { ColumnAttribute attribute = Reflex.GetColumnAttribute(dataRow, propertyInfo); if (attribute != null && dataRow.Table.Columns.Contains(attribute.ColumnNameSaved)) { if (propertyInfo.GetValue(this, null) == null) { dataRow[attribute.ColumnNameSaved] = System.DBNull.Value; } else { dataRow[attribute.ColumnNameSaved] = propertyInfo.GetValue(this, null); } } } }
public void Apply() { foreach (PropertyInfo propertyInfo in Reflex.GetColumnProperties(obj)) { ColumnAttribute a = Reflex.GetColumnAttribute(propertyInfo); if (a != null && this.Row.Table.Columns.Contains(a.ColumnNameSaved)) { if (propertyInfo.GetValue(obj, null) == null) { this.Row[a.ColumnNameSaved] = System.DBNull.Value; } else { this.Row[a.ColumnNameSaved] = propertyInfo.GetValue(obj, null); } } } this.Fill(); }