Entity Framework 6 error while logging the SQLs

5

I am trying to see the SQLs executed by the Entity Framework, I use version 6.

I'm following this guide .

I made a new DBContext using the graphical interface. 5 tables only.

The code is inside a Controller Web API2:

public class TAGsController : ApiController
{
    private MEUDB db = new MEUDB();

    // GET: api/TAGs/5
    [Route("{Key}/api/tag/tag/{id}")]
    [ResponseType(typeof(TAG))]
    public async Task<IHttpActionResult> GetTAG(long id)
    {
        db.Database.Log = Console.Write;
        TAG tAG = await db.TAGs.FindAsync(id);
        if (tAG == null)
        {
            return NotFound();
        }

        return Ok(tAG);
    }

}

When debugging I went to the Find line and it returned the following in the output window:

  

The thread 0x8188 has exited with code 259 (0x103).

What am I doing wrong? According to the guide should be just that.

Edited: More information

When doing everything equal, only using Find() , without Async() , it works.

TAG tAG = await db.TAGs.Find(id);

Is there any extra setting for this? Or any special care?

    
asked by anonymous 17.06.2015 / 14:52

1 answer

2

You can log, not necessarily in console. It can be done in text file, in the Event Viewer , in Trace ... as the idea is to pass delegate , to log in text file, you can use: p>

context.Database.Log = mensagem => File.AppendText("C:\meuarquivodelog.txt").WriteLine(mensagem);
    
17.06.2015 / 17:47