SqlFunctions与DbFunctions

时间:2015-08-20 17:08:44

标签: c# .net linq entity-framework

SqlFunctions声明它应该只在LINQ to Entities中使用。 DbFunctions也是。但是,当我尝试使用SqlFunction时,它会说,DateDiff无法翻译!

为什么呢?它们之间有什么区别(除了方法签名)?它们是否与特定版本相关联?

EDIT1
如果您将DbFunctions替换为SqlFunction,则生成的查询将不会翻译并抛出异常

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;

0 个答案:

没有答案