/// <summary> /// 删除实体类,如果未指定条件,则使用主键值为条件。 /// </summary> /// <returns>条件表达式</returns> public OQL1 Delete() { optFlag = "DELETE "; sqlUpdate = "DELETE FROM [" + this.currEntity.TableName + "] "; oql1 = new OQL1(this.currEntity, this); oql1.Selected = true; return oql1; }
/// <summary> /// 更新实体类的某些属性值,如果未指定条件,则使用主键值为条件。 /// </summary> /// <param name="fields">实体熟悉列表</param> /// <returns>条件表达式</returns> public OQL1 Update(params object[] fields) { optFlag = "UPDATE "; sqlUpdate = "UPDATE [" + this.currEntity.TableName + "] SET "; updateParameters = new Dictionary<string, object>(); foreach (string field in selectedFields) { sqlUpdate += "[" + field + "]=@" + field + ","; updateParameters.Add(field, this.currEntity.PropertyList(field));//某些数据库不支持"@" 格式的参数名称 } sqlUpdate = sqlUpdate.TrimEnd(','); oql1 = new OQL1(this.currEntity, this); oql1.Selected = true; return oql1; }
/// <summary> /// 执行自操作的字段更新,比如为某一个数值性字段执行累加 /// </summary> /// <param name="selfOptChar">自操作类型,有+,-,*,/ 四种类型</param> /// <param name="fields">字段列表</param> /// <returns></returns> public OQL1 UpdateSelf(char selfOptChar, params object[] fields) { if (selfOptChar == '+' || selfOptChar == '-' || selfOptChar == '*' || selfOptChar == '/') { optFlag = "UPDATE "; sqlUpdate = "UPDATE [" + this.currEntity.TableName + "] SET "; updateParameters = new Dictionary<string, object>(); foreach (string field in selectedFields) { sqlUpdate += "[" + field + "]=[" + field + "] " + selfOptChar + " @" + field + ","; updateParameters.Add(field, this.currEntity.PropertyList(field));//某些数据库不支持"@" 格式的参数名称 } sqlUpdate = sqlUpdate.TrimEnd(','); oql1 = new OQL1(this.currEntity, this); oql1.Selected = true; return oql1; } throw new Exception("OQL的字段自操作只能是+,-,*,/ 四种类型"); }
/// <summary> /// 选取实体对象的属性 /// </summary> /// <param name="fields">属性字段列表</param> /// <returns>实体对象查询基本表达式</returns> public OQL1 Select(params object[] fields) { hasSelected = true; if (fields.Length == 0) selectedFields.Clear(); //注意 有可能OQL对象会重复使用,所以下面的事件不能被注销 //this.currEntity.PropertyGetting -= new EventHandler<PropertyGettingEventArgs>(currEntity_PropertyGetting); oql1 = new OQL1(this.currEntity, this); oql1.Selected = true; return oql1; }