public string GetIdentity(MarshalReference marshalReference, MarshalReferenceValue marshalReferenceValue) { IClassMap classMap = Context.DomainMap.MustGetClassMap(marshalReference.Type); StringBuilder id = new StringBuilder(); string sep = classMap.IdentitySeparator; if (sep == "") { sep = "|"; } foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps()) { if (propertyMap.ReferenceType == ReferenceType.None) { MarshalProperty mp = marshalReferenceValue.GetReferenceProperty(propertyMap.Name); id.Append(mp.Value + sep); } else { MarshalReference mr = marshalReferenceValue.GetReferenceReference(propertyMap.Name); id.Append(GetIdentity(mr, marshalReferenceValue) + sep); } } if (id.Length > 0) { id.Length -= sep.Length; } return(id.ToString()); }
public MarshalProperty FromProperty(object sourceObject, IPropertyMap propertyMap) { object value = Context.ObjectManager.GetPropertyValue(sourceObject, propertyMap.Name); MarshalProperty mp = new MarshalProperty(); mp.Name = propertyMap.Name; mp.IsNull = Context.ObjectManager.GetNullValueStatus(sourceObject, propertyMap.Name); if (value == null) { mp.IsNull = true; } if (mp.IsNull == false) { string mpValue = FromPropertyValue(sourceObject, value, propertyMap); if (mpValue != null) { mp.Value = mpValue; } else { mp.IsNull = true; } } if (Context.ObjectManager.HasOriginalValues(sourceObject, propertyMap.Name)) { object orgValue = Context.ObjectManager.GetOriginalPropertyValue(sourceObject, propertyMap.Name); if (orgValue == null || DBNull.Value.Equals(orgValue)) { mp.WasNull = true; } if (mp.WasNull == false) { string mpOrgValue = FromPropertyValue(sourceObject, orgValue, propertyMap); if (mpOrgValue != null) { mp.OriginalValue = mpOrgValue; } else { mp.IsNull = true; } } mp.HasOriginal = true; } else { mp.HasOriginal = false; } mp.IsNull = Context.ObjectManager.GetNullValueStatus(sourceObject, propertyMap.Name); return(mp); }
public object ToPropertyValue(object targetObject, string value, MarshalProperty mp, IPropertyMap propertyMap) { return ToValue(propertyMap, value); }
//TODO: The whole refresh thingy... public void ToProperty(object targetObject, MarshalProperty mp, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior) { IObjectManager om = this.Context.ObjectManager ; IPersistenceManager pm = this.Context.PersistenceManager ; object value = null; if (!mp.IsNull) value = ToPropertyValue(targetObject, mp.Value, mp, propertyMap); bool doWrite = false; bool doWriteOrg = false; RefreshProperty(om, targetObject, propertyMap, pm, refreshBehavior, value, out doWrite, out doWriteOrg); if (doWrite || doWriteOrg) { //To keep inverse management correct, //We really should pick out a ref to any //eventual already referenced object here (in the //case of MergeBehaviorType.OverwriteDirty) //and perform proper inverse management on that object... if (doWrite) { if (mp.IsNull != true) { om.SetPropertyValue(targetObject, propertyMap.Name, value); } Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mp.IsNull); } if (doWriteOrg) { if (mp.HasOriginal) { object orgValue = DBNull.Value ; if (mp.WasNull != true) orgValue = ToPropertyValue(targetObject, mp.OriginalValue,mp, propertyMap); if (propertyMap.ReferenceType == ReferenceType.None) om.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue); else om.SetOriginalPropertyValue(targetObject, propertyMap.Name, value); if (mp.IsNull != mp.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false)) { this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true); //redundant, done once for object by outer caller //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true); } } } // // if (propertyMap.ReferenceType != ReferenceType.None ) // { // // if (value != null) // { // this.Context.IdentityMap.RegisterLoadedObject(value); // // //Inverse management // if (doWrite) // this.Context.InverseManager.NotifyPropertyLoad(refObj, propertyMap, value); // } // } } }
public MarshalProperty FromProperty(object sourceObject, IPropertyMap propertyMap) { object value = Context.ObjectManager.GetPropertyValue(sourceObject, propertyMap.Name); MarshalProperty mp = new MarshalProperty(); mp.Name = propertyMap.Name; mp.IsNull = Context.ObjectManager.GetNullValueStatus(sourceObject, propertyMap.Name); if (value == null) mp.IsNull = true; if (mp.IsNull == false) { string mpValue = FromPropertyValue(sourceObject, value, propertyMap); if (mpValue != null) mp.Value = mpValue; else mp.IsNull = true; } if (Context.ObjectManager.HasOriginalValues(sourceObject, propertyMap.Name)) { object orgValue = Context.ObjectManager.GetOriginalPropertyValue(sourceObject, propertyMap.Name); if (orgValue == null || DBNull.Value.Equals(orgValue)) mp.WasNull = true; if (mp.WasNull == false) { string mpOrgValue = FromPropertyValue(sourceObject, orgValue, propertyMap); if (mpOrgValue != null) mp.OriginalValue = mpOrgValue; else mp.IsNull = true; } mp.HasOriginal = true; } else { mp.HasOriginal = false; } mp.IsNull = Context.ObjectManager.GetNullValueStatus(sourceObject, propertyMap.Name); return mp; }
public object ToPropertyValue(object targetObject, string value, MarshalProperty mp, IPropertyMap propertyMap) { return(ToValue(propertyMap, value)); }
//TODO: The whole refresh thingy... public void ToProperty(object targetObject, MarshalProperty mp, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior) { IObjectManager om = this.Context.ObjectManager; IPersistenceManager pm = this.Context.PersistenceManager; object value = null; if (!mp.IsNull) { value = ToPropertyValue(targetObject, mp.Value, mp, propertyMap); } bool doWrite = false; bool doWriteOrg = false; RefreshProperty(om, targetObject, propertyMap, pm, refreshBehavior, value, out doWrite, out doWriteOrg); if (doWrite || doWriteOrg) { //To keep inverse management correct, //We really should pick out a ref to any //eventual already referenced object here (in the //case of MergeBehaviorType.OverwriteDirty) //and perform proper inverse management on that object... if (doWrite) { if (mp.IsNull != true) { om.SetPropertyValue(targetObject, propertyMap.Name, value); } Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mp.IsNull); } if (doWriteOrg) { if (mp.HasOriginal) { object orgValue = DBNull.Value; if (mp.WasNull != true) { orgValue = ToPropertyValue(targetObject, mp.OriginalValue, mp, propertyMap); } if (propertyMap.ReferenceType == ReferenceType.None) { om.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue); } else { om.SetOriginalPropertyValue(targetObject, propertyMap.Name, value); } if (mp.IsNull != mp.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false)) { this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true); //redundant, done once for object by outer caller //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true); } } } // // if (propertyMap.ReferenceType != ReferenceType.None ) // { // // if (value != null) // { // this.Context.IdentityMap.RegisterLoadedObject(value); // // //Inverse management // if (doWrite) // this.Context.InverseManager.NotifyPropertyLoad(refObj, propertyMap, value); // } // } } }