Page 1 of 1

Reflection CopyDataMembers

Posted: Fri 07 Sep 2012 14:49
by emp51302
Hello can anyone help that why with the new version 7.2 of mysql dotConnect, the following code doesn't work for reflection?

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);


                    }
                }
}

Re: Reflection CopyDataMembers

Posted: Mon 10 Sep 2012 12:19
by StanislavK
We've answered you in the other topic:
http://forums.devart.com/viewtopic.php?t=24838

Re: Reflection CopyDataMembers

Posted: Fri 14 Sep 2012 15:23
by emp51302
Hi - I have sent a response to Mariia with a sample asp.net application which fails with dotConnect 7.2.

Please let me know if a fix is found.

Thank you,

Best,

Re: Reflection CopyDataMembers

Posted: Mon 17 Sep 2012 13:48
by emp51302
Hello - Have we found a fix to the issue I sent your team?

Thank you,

Best,

Re: Reflection CopyDataMembers

Posted: Mon 17 Sep 2012 14:15
by MariiaI