I have a postgres database containing numberous tables. The project is implemented using Entity Framework.
I have 3 database classes lets say A, B & C. Class A contains list of B's objects. Class B contains list of C's objects. Class C is a simple class containing some fields.
Beginning of these classes look like this:
[Table("A")]
public class A: GUIDModelBase
{....
}
Data is filled as below:
Parent1 [A]
-Child1 [B]
--Grandchild1 [C]
--Grandchild2 [C]
-Child2 [B]
--Grandchild3 [C]
--Grandchild4 [C]
For some specific requirement, I retrieve the data of table into an object A using API as below:
A AObj = commonDbService.ARepository.GetAById(A.Id);
GetAById is implemented using dbset as below:
protected DbSet<TEntity> dbset = null;
public Project GetAById(Guid id)
{
return dbset.Include(x => x.CoordinateSystem)
.SingleOrDefault(p => p.Id == id);
}
I want to manipulate(Dont want to have Grandchild2 and Grandchild4) and store the data of AObj in another class object as below:
MigrationData md = new MigrationData();
md.ANewObj = Manipulate(AObj); //Removes two grandchildren elements
When I do this, even AObj gets completely modified too. I need complete data intact in AObj and also in the database table(but temporarily until restart of my application). The table data is shown in one of the UI pages. As soon as its modified as in above lines, the UI page shows only remaining 2 grandchildren. But if i restart my application, all grandchildren are existing in database.
Because of this, I am not able to modify it separately without modifying the base database table. Can anyone help me to get this done ??