I am working on a console application and i am using entity framework as the data access layer.
now currently my main class looks as follow, where i am manully tracking the number of delete, insert and update operations and save them to a database table as follow:-
class SyncPhoneList
{
static void Main(string[] args)
{
string syncResult = "Sync started";
Entities entities = new Entities();
Result r = new Result() { InsertNo=0,ModifyNo=0,DeleteNo=0};
try
{ //code goes here
if (!perIDList.Contains(dbcsvdate.PerID))
{
entities.SyncDatas.Remove(dbcsvdate);
r.DeleteNo++;
}
else if (perIDList.Contains(dbcsvdate.PerName))
{
entities.SyncDatas.Add(dbcsvdate);
r.InsertNo++;
}
else{
entities.Entry(dbcsvdata).State = EntityState.Modified;
r.ModifyNo++;}
}
entities.Result.Add(r);
entities.SaveChanges();
but my question is if there is a better way to track the changies that have being made when i issue entities.SaveChanges()
? i mean does the entities object contain such information ,about the operations it have performed ?
}