Before this was my expression:
var resultado = db.T_CRM_StatusPDV
.Join(db.T_PDV, t1 => t1.DE_Cnpj, t2 => t2.CNPJ, (t1, t2) => new { t1, t2})
.Where(dt => (TimeSpan)((dt.t1.DT_TransacaoV - DateTime.Now)).TotalDays > 45
&& dt.t2.DataCadastro >= dataInicio && dt.t1.DT_ControleV >= dataControle)
.Select(i => new { i.t1.DE_Cnpj }).ToList();
This caused this error:
DbArithmeticExpression arguments must have a numeric common type.
I changed to this expression:
var resultado = db.T_CRM_StatusPDV
.Join(db.T_PDV, t1 => t1.DE_Cnpj, t2 => t2.CNPJ, (t1, t2) => new { t1, t2})
.Where(dt => EntityFunctions.DiffHours(dt.t1.DT_TransacaoV,DateTime.Now) > 45
&& dt.t2.DataCadastro >= dataInicio && dt.t1.DT_ControleV >= dataControle)
.Select(i => new { i.t1.DE_Cnpj }).ToList();
And now I have this error:
LINQ to Entities does not recognize the method 'System.Nullable'1[System.Int32] DiffHours(System.Nullable'1[System.DateTime], System.Nullable'1[System.DateTime])' method, and this method cannot be translated into a store expression.
How can I calculate time in a lambda expression or linq to entities?