C# System.Linq.Dynamic.ParseException:';操作员'&燃气轮机';与操作数类型不兼容';日期时间?';和';Int32'';
如何正确解析sdateC# System.Linq.Dynamic.ParseException:';操作员'&燃气轮机';与操作数类型不兼容';日期时间?';和';Int32'';,c#,entity-framework,linq,parsing,dbset,C#,Entity Framework,Linq,Parsing,Dbset,如何正确解析sdate IQueryable bddata = Junior2KepwareContext.Set(type) .Where($"C_NUMERICID == {idLinea}") .Where("C_TIMESTAMP > "+ startDate ) .OrderBy("C_TIMESTAMP"); System.Linq.Dynamic.ParseException:'运算符'>'与操作数类型'DateTime'和'
IQueryable bddata = Junior2KepwareContext.Set(type)
.Where($"C_NUMERICID == {idLinea}")
.Where("C_TIMESTAMP > "+ startDate )
.OrderBy("C_TIMESTAMP");
System.Linq.Dynamic.ParseException:'运算符'>'与操作数类型'DateTime'和'Int32'不兼容
您需要使用以下参数:
IQueryable bddata = Junior2KepwareContext.Set(type)
.Where($"C_NUMERICID == {idLinea}")
// @0 is first parameter in the list, @1 is second etc
.Where("C_TIMESTAMP > @0", startDate) // startDate is of type DateTime, not string
.OrderBy("C_TIMESTAMP");
始终使用参数而不是内联值是一种很好的做法(例如,也可以将其用于
idLinea
)您已经有了日期时间,那么为什么要进行分析。@mjwillsidLinea
是一个byteMaybe,我缺少了一些东西,但是你不应该把回调传递给where和orderby方法吗?@MassimoVariolo嗯,因为我想它是这样设计的。当您使用参数时,解析器知道它们的正确类型(在本例中,它看到startDate
是DateTime
),并且能够构建正确的查询。如果您不使用参数-有时它可以生成正确的查询(例如,如果您使用普通数字),有时则不使用。因此,为了避免所有问题,只需始终使用参数。