Reflection CopyDataMembers

Reflection CopyDataMembers

Postby emp51302 » Fri 07 Sep 2012 14:49

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


                    }
                }
}
emp51302
 
Posts: 46
Joined: Fri 19 Aug 2011 20:57

Re: Reflection CopyDataMembers

Postby StanislavK » Mon 10 Sep 2012 12:19

We've answered you in the other topic:
http://forums.devart.com/viewtopic.php?t=24838
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Re: Reflection CopyDataMembers

Postby emp51302 » Fri 14 Sep 2012 15:23

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,
emp51302
 
Posts: 46
Joined: Fri 19 Aug 2011 20:57

Re: Reflection CopyDataMembers

Postby emp51302 » Mon 17 Sep 2012 13:48

Hello - Have we found a fix to the issue I sent your team?

Thank you,

Best,
emp51302
 
Posts: 46
Joined: Fri 19 Aug 2011 20:57

Re: Reflection CopyDataMembers

Postby MariiaI » Mon 17 Sep 2012 14:15

MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for MySQL