is it possible to see the execution order of the entity?

2

So, is it possible for me to look at the execution order of Querys that Entity Framework mounts?

My problem is that it is trying to make a deletion in the wrong order, even after I make the calls in the order that sql server works.

Code:

itensPVF.ForEach(e => this.pvfService.RemoverPorChave(e.Chave));                        
RemoverItemSolicitado(chaveOS, numeroItensPvf);

In this case, this itemPVF has to be erased first because of its relationship with the table that is deleted in sequence, only at the time of commit by entity , it does not understand in this way and it error :

  

{"The DELETE statement conflicted with the REFERENCE constraint \"FK_TB_ITEM_OS_PVF_TB_ITEM_SOLICITADO\". The conflict occurred in database \"BANCO\", table \ "dbo.TB_ITEM_OS_PVF\", column 'CD_ITEM_SOLICITADO'. \r\nThe statement has been terminated."}

    
asked by anonymous 20.12.2016 / 21:50

1 answer

2
  

So, is it possible for me to look at the execution order of Querys that Entity Framework mounts?

Yes, it is possible to audit the with < Database.Log :

var db = new Contexto();
db.Database.Log = x => System.Console.WriteLine(x);

After these lines do the process you want, when executing commands will show an output on your console screen.

Note: This code example is to be done in Console Application , but nothing prevents it from being used in many contexts.

You also have a tool that you can use to SQL Server Profiler , you have more features and brings a lot of information about what's happening in SQLServer . According to MSDN - Site Developer Network , SQL Server Profiler is an interface for creating and managing traces and analyzing and reproducing trace results .

References:

20.12.2016 / 22:09