我需要在ServiceStack中使用OrmLite将DateTime
值与datetime字段进行比较。
我已经访问过多个线程,但之前没有在此主题中指定任何内容。我有的OrmLitte SQL就像:
Db.Select<Table1>(q => q.Where(x => x.creationDate >= creationDate));
答案 0 :(得分:2)
你为什么不尝试创建一个poco:
public class Table1 // or Person for example
{
public string Id {get; set;}
public string Name {get; set;}
public DateTime Dob {get; set;}
}
然后你可以这样做:
var creationDate = DateTime.Now.AddDays(-10);
Db.Select<Table1>(q => q.Where(p => p.Dob.Date >= creationDate.Date));
答案 1 :(得分:0)
您应该使用原始sql 来实现此目标
这样的事情:
var query = db.From<Table1>();
var date = query.CreateParam("date", creationDate, dbType: DbType.Date);
query.Params.Add(date);
query.UnsafeWhere("CAST(creationDate AS DATE) = CAST(@date AS DATE)");
return db.Select(query)
或者这个:
var date = db.CreateParam("date", creationDate, dbType: DbType.Date);
return db.Select<Table1>("SELECT * FROM Table1 WHERE CAST(creationDate AS DATE) = CAST(@date AS DATE)", new[] { date });