Is it possible to see the Entity execution order?

Asked

Viewed 42 times

2

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

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 deleted first on account of its relationship with the table that is deleted in sequence, only at the time of the commit for entity, he does not understand this way and bursts the 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."}

  • 1

    What is your context?

  • What is pvrService? What’s in the code for RemoverPorChave?

  • pvrService is my business rule service, removerPorChave is a Generics that will eventually call . Remove.

1 answer

2


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

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

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

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

Observing: this code example is to be performed in Console Application, but, nothing prevents to be used in various contexts.

You also have a tool that can be used for SQL Server Profiler, has more resources and brings a lot of information about what is happening on SQLServer. According to MSDN - Website Developer Network, SQL Server Profiler is an interface to create and manage tracking and analyze and reproduce tracking results.

References:

  • 1

    This will help and much, thanks my dear.

  • 1

    In addition to the way you mentioned, I was able to see the Entity execution log through an SQL Server tool, called SQL Server Profile.

  • Perfect @Sondotnet I’ve used myself is perfect ... I’ll use your comment and edit the answer to get as complete as possible

Browser other questions tagged

You are not signed in. Login or sign up in order to post.