I have a table in Code First in Entity Framework
public class Foo
{
public string A;
public string B;
}
I am trying to update table Foo in the database
Foo foo2 = new Foo
{
A = "a",
B = "b"
};
Foo foo1= db.Foo.Find(1);
foo1 = foo2;
and i know foo1 = foo2
wont work because EF will track the reference of foo1
and with
foo1 = foo2
foo1
will get the reference of foo2
and update works if i assign new value to the object one by one
foo1.A = foo2.A;
foo1.B = foo2.B
but is there any way I can achieve this just by copying the data from one object to second? Thanks
so far I have tried this: Shallow Copy
public Foo Clone()
{
return (Foo)this.MemberwiseClone();
}
but still
foo1 = foo2.Clone();
is not working