Select in Entity Framework is not working

0

I am doing a query using LINQ, very simple query I am using the following method.

public void verificaAcesso( string usuario, string senha)
{
    using (DbBancoContext banco = new DbBancoContext())
    {
        var resultadoConsulta = from u in banco.USUARIOS_PROCESSO
                                where
                                   u.USUARIO == usuario
                                   && u.SENHA == senha
                                   && u.DT_CANCELAMENTO != null
                                select u.ID_USUARIO;
    }
}

I'm not getting any feedback, but when I check the contents of the resultadoConsulta variable it displays the following content.

{SELECT [Extent1].[ID_USUARIO] AS [ID_USUARIO]
 FROM [dbo].[USUARIOS_PROCESSO] AS [Extent1]
 WHERE ([Extent1].[USUARIO] = @p__linq__0) AND ([Extent1].[SENHA] = @p__linq__1) AND ([Extent1].[DT_CANCELAMENTO] IS NOT NULL)}

What am I doing wrong?

    
asked by anonymous 10.10.2014 / 18:52

1 answer

3

Add a line:

var idsUsuarios = resultadoConsulta.ToList(); The result will be in idsUsuarios .

Or wrap your query by parentheses by adding a call to ToList :

    var resultadoConsulta = (from u in banco.USUARIOS_PROCESSO
                            where
                               u.USUARIO == usuario
                               && u.SENHA == senha
                               && u.DT_CANCELAMENTO != null
                            select u.ID_USUARIO).ToList();

and then the result will be in resultadoConsulta .

What your code does so far is just creating the query and not executing it.

    
10.10.2014 / 19:16