-3

Can anyone help me with the following error?

LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression.

enter image description here

Below is my code, I am trying in several ways to fix this error, but I have not been successful:

public IEnumerable<Dia1> GetPendenciasByUser(int centroId)
{
    var query = Db.Dia1S
        .Join(Db.Cadastros, dia1 => dia1.PatientId, cad => cad.PatientId, (dia1, cad) => new { dia1, cad })
        .Join(Db.Randomizacao, dia1 => dia1.dia1.PatientId, rand => rand.PatientId, (dia1, rand) => new { dia1, rand })
        .Where(s => s.dia1.dia1.dtd1 == null ? (Convert.ToInt32(DateTime.Now - s.rand.RandomizacaoData)) > 1 : (Convert.ToInt32(Convert.ToDateTime(s.dia1.dia1.dtd1) - s.rand.RandomizacaoData)) > 1 )
        .Select(s => s.dia1.dia1)
        .ToList();
    return query;
}
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55

1 Answers1

0

The error message is clear, LINQ doesn't know how to convert the Convert.ToInt32() function to SQL. You can either use direct casting like this:

(int)(DateTime.Now - s.rand.RandomizacaoData)

Or you'll have to execute the query and get the data, then convert it in memory using Convert.ToInt32() as you wish.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55