一、在使用Linq时,想要比较字符串类型的日期时,参考以下:
SQL语句:
1)select * from TableName where StartTime > '2015-04-08'
2)select * from TableName where StartTime >= '2015-04-08'
3)select * from TableName where StartTime < '2015-04-08'
4)select * from TableName where StartTime <= '2015-04-08'
lambda表达式写法:
).Where(a => a.StartTime.CompareTo('2015-04-08') > )
).Where(a => a.StartTime.CompareTo('2015-04-08') >= )
).Where(a => a.StartTime.CompareTo('2015-04-08') < )
).Where(a => a.StartTime.CompareTo('2015-04-08') <= )
更规范的写法:
).Where(a => String.Compare(a.StartTime, '2015-04-08', StringComparison.Ordinal) > )
).Where(a => String.Compare(a.StartTime, '2015-04-08', StringComparison.Ordinal) >= )
).Where(a => String.Compare(a.StartTime, '2015-04-08', StringComparison.Ordinal) < )
).Where(a => String.Compare(a.StartTime, '2015-04-08', StringComparison.Ordinal) <= )
二、但是,又遇到Linq延时查询的问题。