2

I know how to show underlying SQL query in EF Core. But what that shows me is like:

UPDATE [tow_base] 
SET [speed] = @p75, 
    [date_last_modified] = @p76, 
    [miles_per_division] = @p77, 
    [owner_user] = @p78
WHERE [tow_id] = @p81;

That particular query was generated in context.SaveChanges(), so I am not directly setting the parameters.

I can execute that query in any SQL client, with the values I think are in there, and it works. There are also value converters involved in many of those fields, which means the values I have stored in the record being updated are not going to be the same types as the parameters passed to the database UPDATE statement.

Is there any way I can see exactly what those @p variables are (particularly their declared type)?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Auspex
  • 2,175
  • 15
  • 35

1 Answers1

2

You can use EnableSensitiveDataLogging() when configuring your DB context like this:

services
 .AddDbContext<ContactsContext>(options =>
 {                         
   options.UseSqlServer(/*whatever*/);
   options.EnableSensitiveDataLogging();
 });

But be aware not to share these logs around, it's better to wrap the call of EnableSensitiveDataLogging in #if DEBUG or if(app.Environment.IsDevelopment()).

Dmitry Arestov
  • 1,427
  • 12
  • 24
  • I thought `EnableSensitiveDataLogging` was already the default in `Development`. After all, when you get a stack trace in production, it _suggests_ using `EnableSensitiveDataLogging` – Auspex May 09 '23 at 17:05
  • Indeed, you're right. This is showing me exactly what I wanted (I'm not sure it's showing me what I _need_ -- at least at first glance the numbers look right, but that just means I'm looking in the wrong place!) – Auspex May 09 '23 at 20:58