我正在使用 System.Linq.Dynamic 从 .Net MVC 1.0 中的 ajax 调用中自定义 where 子句。
它适用于字符串、int 等,但不适用于 DateTime,我得到异常无法将 String 与 DateTime 进行比较。非常简单的测试代码是
items = items.Where(string.Format(@" {0} > {1}{2}{1} ", searchField, delimiter, searchString));
例如,其中 searchField 将是 start_date 并且数据类型是 DateTime,分隔符是 "(也没有尝试过),并且 searchString 将是 01-Jan-2009(也尝试过 01/01/2009)并且 items 是来自的 IQueryable LinqToSql。
有没有办法在动态 where 中指定数据类型,或者有更好的方法。它目前已经在使用一些反射来确定需要什么类型的分隔符。