All I am trying to do is copy source object to destination to clone it that way It creates a duplicate copy of it. This all seems to work with version 6.80.325 release.
But after the reference to System.Data.Linq was removed, I am not able to CopyDataMembers
from source to destination
Code: Select all
public static void CopyDataMembers(DataContext dc, object sourceEntity, object targetEntity){
IEnumerable<MetaDataMember> dataMembers =
from mem in dc.Mapping.GetTable(sourceEntity.GetType()).RowType.DataMembers
where mem.IsAssociation == false
select mem;
//IEnumerable<MetaDataMember> primaryKeyMembers = dc.Mapping.GetTable(typeof(TSource)).RowType.DataMembers.AsQueryable().Where(mem => mem.IsPrimaryKey == true);
//go through the list of members and compare values
foreach (MetaDataMember mem in dataMembers)
{
object originalValue = mem.StorageAccessor.GetBoxedValue(targetEntity);
object newValue = mem.StorageAccessor.GetBoxedValue(sourceEntity);
//check if the value has changed
if (newValue == null && originalValue != null || newValue != null && !newValue.Equals(originalValue))
{
//use reflection to update the target
System.Reflection.PropertyInfo propInfo = targetEntity.GetType().GetProperty(mem.Name);
propInfo.SetValue(targetEntity, propInfo.GetValue(sourceEntity, null), null);
}
}
}