public void SetValue() { if (association == null) { return; } object value1 = propertyInfo1.GetValue(dpoInstance, null); SqlCmd cmd = new SqlCmd(this.clause2); cmd.AddParameter(association.Column1.SqlParameterName(), value1); DataTable dataTable = cmd.FillDataTable(); if (mappingType == MappingType.One2One) { //if association object was not instatiated if (propertyInfo2.GetValue(this, null) == null) { PersistentObject dpo = (PersistentObject)Activator.CreateInstance(propertyInfo2.PropertyType, null); dpo.FillObject(dataTable.Rows[0]); propertyInfo2.SetValue(this, dpo, null); } else { IDPObject dpo = (IDPObject)propertyInfo2.GetValue(this, null); dpo.FillObject(dataTable.Rows[0]); } } else { //if association collection was not instatiated if (propertyInfo2.GetValue(this, null) == null) { propertyInfo2.SetValue(this, Activator.CreateInstance(propertyInfo2.PropertyType, new object[] { dataTable }), null); } else { IPersistentCollection collection = (IPersistentCollection)propertyInfo2.GetValue(this, null); collection.Table = dataTable; } } }
public void FillIdentity() { if (association == null) { return; } if (!IsColumn1Identity()) { return; } if (mappingType == MappingType.One2Many) { object value1 = propertyInfo1.GetValue(dpoInstance, null); IDPCollection collection = (IDPCollection)propertyInfo2.GetValue(this, null); foreach (DataRow row in collection.Table.Rows) { row[association.Column2] = value1; IDPObject dpo = (IDPObject)collection.GetObject(row); dpo.FillIdentity(row); } } }