3

SqlFunctions states that it should be used only in LINQ to Entities. DbFunctions also. But when I try SqlFunctions it says that, for example, DateDiff cannot be translated!

Why? What is the difference (besides methods signatures) between them? Are they tied to a specific version?

Edit1
If you replace DbFunctions for SqlFunction the resulting query wont translate and throw a exception

case "<>":
    return a => a.id_indice == indice.id && indice.tipoDado == (int)enumTipo.Data && DbFunctions.DiffDays(a.valorDateTime, data) == 0;
case ">":
    return a => a.id_indice == indice.id && indice.tipoDado == (int)enumTipo.Data && DbFunctions.DiffDays(a.valorDateTime, data) > 0;
case "<":
    return a => a.id_indice == indice.id && indice.tipoDado == (int)enumTipo.Data && DbFunctions.DiffDays(a.valorDateTime, data) < 0;
case ">=":
    return a => a.id_indice == indice.id && indice.tipoDado == (int)enumTipo.Data && DbFunctions.DiffDays(a.valorDateTime, data) >= 0;
case "<=":
    return a => a.id_indice == indice.id && indice.tipoDado == (int)enumTipo.Data && DbFunctions.DiffDays(a.valorDateTime, data) <= 0;
Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • 1
    Just a guess: `SqlFunctions` is for LINQ-to-SQL, while `DbFunctions` is for Entity Framework. – Lucas Trzesniewski Aug 20 '15 at 17:17
  • 3
    I believe your question is answered here. Just keep in mind, EntityFunctions is now DbFunctions as of EF6. http://stackoverflow.com/questions/15637317/what-is-the-difference-between-sqlfunctions-and-entityfunctions – Vahlkron Aug 20 '15 at 17:23
  • DateDiff is expecting 3 parameters, I updated my answer. – Akash Kava Aug 20 '15 at 17:49
  • What are you actually asking? If it's about the exception you should show the code and the exception. – Gert Arnold Aug 20 '15 at 20:44

0 Answers0