0

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 ? }

John John
  • 1
  • 72
  • 238
  • 501
  • Possible duplicate of [How can I log the generated SQL from DbContext.SaveChanges() in my Program?](http://stackoverflow.com/questions/16880687/how-can-i-log-the-generated-sql-from-dbcontext-savechanges-in-my-program) – tukaef Apr 05 '16 at 17:01
  • @2kay the link you are referencing is talking about EF6 while in my case i am using EF5.. – John John Apr 05 '16 at 17:16
  • 1
    There used to be [this](http://stackoverflow.com/q/15829898/861716) pretty elaborate solution. The only one afaik. – Gert Arnold Apr 05 '16 at 21:20

0 Answers0