//---------------------------------------------------------- public virtual void Assign(TMetaEntity me, CEntity rhs) { TMetaTable mt = me.MetaTable; TInheritMappingType inheritType = mt.InheritMappingType; TMetaColumnCollection mcs = null; if (inheritType == TInheritMappingType.TablePerConcreteClass) { mcs = mt.FullValueColumns; } else if (inheritType == TInheritMappingType.TablePerSubClass) { mcs = mt.ValueColumns; } CEntity that = rhs as CEntity; foreach (TMetaColumn mc in mcs) { //if (!cm.IsAssign) // continue; if (mc.MemberName == "Captions.Cn (Assign)") { System.Diagnostics.Debug.WriteLine(mc.MemberName); } object v2 = that.GetEpoPropertyValue(mc); this.SetEpoPorpertyValue(mc, v2); } }
//--------------------------------------------------------------------- public virtual void Pull(CEntity ety, DataRow row, TMetaColumn mc) { string columnName = mc.ColumnName; //if(columnName=="A1623") { // Debug.WriteLine("XXX"); //} object v0 = row[columnName]; //TODO: how to know nullable property /// System.Nullable int? No; if (mc.IsGenericType) { if (v0 == DBNull.Value) { ety.SetEpoPorpertyValue(mc, null); } else { ety.SetEpoPorpertyValue(mc, v0); } return; } object customNullValue = mc.MappingAttribute.NullValue; if (customNullValue == null) { object v1 = TConvert.DbValue2DataValue(mc.DataType, v0); /// most hit here! ety.SetEpoPorpertyValue(mc, v1); return; } /// CustomNullValue //TODO: customNullValue!=null issues, not finished.... Type underlyingType = mc.UnderlyingType; if (customNullValue.GetType() != underlyingType) { if (underlyingType == typeof(Decimal)) { // float to decimal string to decimal Decimal d = Convert.ToDecimal(customNullValue); object v2 = TConvert.DbValue2DataValue(underlyingType, row[columnName], d); ety.SetEpoPorpertyValue(mc, v2); } else { throw new TException("nullValue.GetType() differ value.GetType"); } } else { object v3 = TConvert.DbValue2DataValue(underlyingType, row[columnName], customNullValue); ety.SetEpoPorpertyValue(mc, v3); } }
//-------------------------------------------------------------- public bool Equals(Type t, object rhs) { if (rhs == null) { return(false); } if (object.ReferenceEquals(this, rhs)) { return(true); } if (this.GetType() != rhs.GetType()) { return(false); } CEntity that = rhs as CEntity; if (that == null) { return(false); } TMetaEntity meta = TMetaRegistry.Default.GetMeta(t); TMetaTable mt = meta.MetaTable; TInheritMappingType inheritType = mt.InheritMappingType; TMetaColumnCollection mcs = null; if (inheritType == TInheritMappingType.TablePerConcreteClass) { mcs = mt.FullValueColumns; } else if (inheritType == TInheritMappingType.TablePerSubClass) { mcs = mt.ValueColumns; } bool b = true; foreach (TMetaColumn mc in mcs) { //if (!cm.IsCompare) // continue; if (mc.MemberName == "Captions.Cn (Equal)") { System.Diagnostics.Debug.WriteLine(mc.MemberName); } object v1 = this.GetEpoPropertyValue(mc); object v2 = that.GetEpoPropertyValue(mc); b = b && (object.Equals(v1, v2)); } b = b && (PersistState == that.PersistState); return(b); }
//--------------------------------------------------------------------- public virtual void Pull(CEntity e, DataRow row) { TMetaEntity meta = GetMetaEntity(this.GetType()); foreach (TMetaColumn mc in meta.MetaTable.FullValueColumns) { if (!row.Table.Columns.Contains(mc.ColumnName)) { continue; } Pull(e, row, mc); } }
//---------------------------------------------------------- public override void Assign(object rhs) { CEntity that = rhs as CEntity; TMetaEntity meta = GetMetaEntity(this.GetType()); foreach (TMetaColumn mc in meta.MetaTable.FullValueColumns) { //if (mc.ColumnName == "CAPTIONS_CN") // System.Diagnostics.Debug.WriteLine(mc.ColumnName); object v = that.GetEpoPropertyValue(mc); this.SetEpoPorpertyValue(mc, v); } }
//-------------------------------------------------------------- // TODO: Distinguish between Equals/Equal public override bool Equals(object rhs) { if (rhs == null) { return(false); } if (object.ReferenceEquals(this, rhs)) { return(true); } if (this.GetType() != rhs.GetType()) { return(false); } CEntity that = rhs as CEntity; if (that == null) { return(false); } TMetaEntity me = GetMetaEntity(this.GetType()); if (me == null) { return(base.Equals(rhs)); } bool b = true; foreach (TMetaColumn mc in me.MetaTable.FullValueColumns) { //if (!cm.IsCompare) // continue; object v1 = this.GetEpoPropertyValue(mc); object v2 = that.GetEpoPropertyValue(mc); b = b && (object.Equals(v1, v2)); } //b = b && (PersistState == that.PersistState); return(b); }
//--------------------------------------------------------------------- public virtual void Pull(CEntity e, DataRow row, TMetaEntity me) { TInheritMappingType inheritType = me.MetaTable.InheritMappingType; if (inheritType == TInheritMappingType.TablePerConcreteClass) { foreach (TMetaColumn mc in me.MetaTable.FullValueColumns) { Pull(e, row, mc); } } else if (inheritType == TInheritMappingType.TablePerSubClass) { foreach (TMetaColumn mc in me.MetaTable.ValueColumnsWithId) { Pull(e, row, mc); } } }
//--------------------------------------------------------------------- public CEntity(CEntity parent) { Parent = parent; InitObject(); }
//--------------------------------------------------------------------- public virtual void Load(CEntity entity) { throw new NotImplementedException(); }
//---------------------------------------------------------- public virtual void Assign(Type t, CEntity rhs) { TMetaEntity me = TMetaRegistry.Default.GetMeta(t); Assign(me, rhs); }