任何人都知道我的语法有什么问题吗?在尝试为 DateTime 数据类型设置 where 条件时,我正在进行动态 eSQL 查询并遇到错误。这是错误:
查询语法无效。近期“2011”,第 1 行,第 135 列。
如果重要的话,我的实体中的 DateTime 类型实际上是可为空的 DateTime?
但是,我认为这是我读过的所有内容的正确语法。
这是代码:
List<EntityFilter<FirstRead>> filters = new List<EntityFilter<FirstRead>>()
{
new EntityFilter<StudyFirstRead> { PropertyName = "username", OpType = ExpressionType.Equal, Value = "cwoodhouse" },
new EntityFilter<StudyFirstRead> { PropertyName = "FirstRead", OpType = ExpressionType.LessThan, Value = "DATETIME'2011-02-01 00:00'" }
};
EntityFilter 在哪里:
public class EntityFilter<T>
{
public string PropertyName { get; set; }
public ExpressionType OpType { get; set; }
public object Value { get; set; }
我正在构建这样的动态查询:
StringBuilder builder = new StringBuilder();
int counter = 0;
string baseStr = @"SELECT VALUE val FROM " + contextName + "." + tableName + " AS val WHERE val.";
builder.Append(baseStr);
foreach (EntityFilter<T> filter in filters)
{
//builder.Append(filter.PropertyName + " " + filter.OpTypeString() + " @p" + counter);
builder.Append(filter.PropertyName + " " + filter.OpTypeString() + "'" + filter.Value + "'");
counter++;
if (counter < filters.Count)
builder.Append(" AND val.");
else
{
break;
}
}
return builder.ToString();