Hi All
I am creating a clone of an object using reflection. But at the end of the method, when I call dataContext.GetChangeSet(), it gives inserts:1.
Here is the code:
MyDataContext dataContext = new MyDataContext();
dataContext.Connection.Open();
dataContext.Transaction = dataContext.Connection.BeginTransaction();
DeliveryRegistration dr = null;
try
{
DeliveryRegistration oldRegistration = null;
object obj = null;
string error = "";
if (Utility.EmailNotificationsEnabled)
{
oldRegistration = RAKBankDataAccess.GetRegistrationById(dataContext, int.Parse(Request.QueryString["Id"]));
if (Utility.CreateCopy((object)oldRegistration, out obj, out error))
{
oldRegistration = (DeliveryRegistration)obj;
}
}
And the CreateCopy method at the end of which datacontext has 1 inserts
public static bool CreateCopy(object orignal, out object newCopy, out string error)
{
error = "";
try
{
Type t = orignal.GetType();
ConstructorInfo[] constructors = t.GetConstructors();
newCopy = constructors[0].Invoke(null);
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo prop in props)
{
if(prop.CanRead && prop.CanWrite && !prop.PropertyType.IsArray)
{
prop.SetValue(newCopy, prop.GetValue(orignal, null), null);
}
}
catch (Exception ex)
{
newCopy = null;
return false;
}
return true;
}
On submitting changes, a new entry is also created. Any Idea what might be causing this ?