0
I have this method that makes me a select but it does not return me anything.
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public JsonResult GetContratos()
{
     List<object> resultado = new List<object>();
     var contratos = db.Contratos.Where(c => c.Tipo != "N").Select(c => c.Id);
     foreach (string contrato in contratos)
     {
          resultado.Add(new { id = contrato, value = contrato });
     }
     return Json(resultado, JsonRequestBehavior.AllowGet);
}
I already tried to put the . Tolist() at the end and nothing
The SQL that is returned to me in the variable var contratos, when I run it on sql server works perfectly, it brings me back given, but on c# it brings me nothing.
{SELECT 
    1 AS [C1], 
    [Extent1].[Id] AS [Id], 
    [Extent1].[DtCriacao] AS [DtCriacao], 
    [Extent1].[DtInicioValidade] AS [DtInicioValSELECT 
    [Extent1].[Id] AS [Id]
    FROM [dbo].[Contrato] AS [Extent1]
    WHERE  NOT ((N'N' = [Extent1].[Tipo]) AND ([Extent1].[Tipo] IS NOT NULL))

var contrtatosis null?– Leandro Angelo
It is not null, that is the sql that comes from it
– gabrielfalieri
What happens if you remove Where :
var contratos = db.Contratos.Select(c => c.Id);? Are you sure you are connected to the correct base?– William John Adam Trindade
I have tried to take also, and yes is connected on the correct base
– gabrielfalieri
Nothing happens when I take off the Where
– gabrielfalieri
Yes, it is, because it already has a login system in place and some other things that depend on the bank
– gabrielfalieri
@Williamjohnadamtrindade can help me?
– gabrielfalieri
Start with the simplest step. Return the complete list:
var contratos = db.Contratos;– William John Adam Trindade
Nor is this returning anything
– gabrielfalieri
Are you sure that Entity is connecting on the same basis that you are doing the query on? E.g.: you run the Query manually in the Sqlserver homologation, but your application is pointing to a Localdb or other database.
– Leandro Angelo