Well, the best way to do this select, involving an entity and the user table (to fetch the user who last worked in the registry) I found, was this:
protected override void Retrieve()
{
base.Retrieve();
_context = new DBConecta(this.strConecta);
var _query = from r in _context.CNAES
from u in _context.Usuarios
where u.id == r.usuario_id
select new { r.id, r.nome, r.ativo, r.created_at, r.updated_at, r.usuario_id, usuarioNome = r.usuario.login };
dbGride.DataSource = _query.ToList();
AfterRetrieve();
}
Doing so, it does not bring all the fields of the users table and yes only the field that I requested. This is very important since a large table, bringing all the data from another referenced table can have a cost!
SELECT
Extent1
. id
,
Extent1
. nome
,
Extent1
. ativo
,
Extent1
. created_at
,
Extent1
. updated_at
,
Extent1
. usuario_id
,
Extent2
. primeiro_nome
FROM cnaes
AS Extent1
INNER JOIN Usuarios
AS Extent2
ON Extent1
. usuario_id
= Extent2
. id
- Executing at 03/13/2016 16:54:36 -03: 00
- Completed in 0 ms with result: EFMySqlDataReader
For me this was the best solution.