/// <summary> /// 构造主键的过滤条件。 /// </summary> /// <param name="context">SQL构造上下文信息。</param> /// <param name="sqlInfo">SQL拼装的中间变量。</param> /// <param name="currentObject">主键过滤条件对应的领域对象</param> /// <param name="pkColumnData">主键值Dictionary,Key是ElemetID,Value是列的值。</param> /// <param name="IsUseFieldPrefix">是否使用列全名。</param> /// <returns>主键过滤条件</returns> protected SqlPrimaryKey GetPrimaryKeyConditions(SqlBuildingContext context, SqlBuildingInfo sqlInfo, DomainObject currentObject, IDictionary <string, object> data, bool IsUseFieldPrefix = false) { var curDataObject = currentObject.DataObject; var tableName = context.DataObjectTableMapping[curDataObject.ID]; SqlTable curTable = this.FindSqlTable(tableName, sqlInfo); if (curTable == null) { curTable = new SqlTable(tableName, tableName, tableName); this.RegistSqlTable(tableName, curTable, sqlInfo); } //var data = context.DataContext.GetCurrentDataContextItem(currentObject.ID); var primaryKey = new SqlPrimaryKey(); foreach (var column in curDataObject.PKColumns) { var keyField = new SqlPrimaryKeyField(curTable, column.ColumnName); var pkElement = currentObject.Elements.FirstOrDefault(i => i.DataColumnID == column.ID); keyField.Value.Value = data[pkElement.ID]; keyField.IsUseFieldPrefix = true; primaryKey.ChildCollection.Add(keyField); } return(primaryKey); }
/// <summary> /// 获取CO上某GSPNode的GSPAbsDBTable主键的过滤条件。 /// </summary> /// <param name="context">SQL构造上下文信息。</param> /// <param name="sqlInfo">SQL拼装的中间变量。</param> /// <param name="coNode">主键过滤条件对应的GSPNode。</param> /// <param name="dbTable">主键过滤条件对应的GSPAbsDBTable。</param> /// <param name="IsUseFieldPrefix">是否使用表名</param> /// <returns>主键的过滤条件。</returns> protected string GetPrimaryKeyCondition(SqlBuildingContext context, SqlBuildingInfo sqlInfo, DomainObject coNode, bool IsUseFieldPrefix = false) { var tableName = context.TableName; var tableKey = tableName; var sqlPrimaryKey = new SqlPrimaryKey(); var sqlTable = this.TryFindAndRegistSqlTable(tableKey, tableName, tableName, tableName, sqlInfo); var pkColumnData = context.DataContext.GetCurrentDataContextItem(context.Node.ID).PrimaryKeyData; foreach (DataColumn item in context.DataObject.PKColumns) { var pkElement = context.Node.Elements.FirstOrDefault(i => i.DataColumnID == item.ID); if (pkElement == null) { throw new Exception("Cannot find PkElement, Column ID: " + item.ID); } if (pkColumnData.ContainsKey(pkElement.ID)) { var keyField = new SqlPrimaryKeyField(); keyField.Table = sqlTable; keyField.FieldName = item.ColumnName; keyField.Value.Value = pkColumnData[pkElement.ID]; keyField.IsUseFieldPrefix = IsUseFieldPrefix; sqlPrimaryKey.ChildCollection.Add(keyField); } } return(sqlPrimaryKey.ToSQL()); }
/// <summary> /// 获取主键过滤条件。 /// </summary> /// <param name="context">SQL构造上下文信息。</param> /// <param name="domainObject">领域对象</param> /// <param name="curDataObject">数据对象</param> /// <param name="sqlInfo">SQL拼装的中间变量。</param> /// <returns>主键的过滤条件。</returns> private SqlPrimaryKey GetPrimaryKeyCondition(SqlBuildingContext context, DomainObject domainObject, DataObject curDataObject, SqlBuildingInfo sqlInfo) { var tableName = context.DataObjectTableMapping[curDataObject.ID]; SqlTable curTable = this.FindSqlTable(tableName, sqlInfo); if (curTable == null) { curTable = new SqlTable(tableName, tableName, tableName); this.RegistSqlTable(tableName, curTable, sqlInfo); } var data = context.DataContext.GetCurrentDataContextItem(domainObject.ID); if (data.PrimaryKeyData.Count == 0) { return(null); } var primaryKey = new SqlPrimaryKey(); foreach (var column in curDataObject.PKColumns) { var keyField = new SqlPrimaryKeyField(curTable, column.ColumnName); var pkElement = domainObject.Elements.FirstOrDefault(i => i.DataColumnID == column.ID); keyField.Value.Value = data.PrimaryKeyData[pkElement.ID]; keyField.IsUseFieldPrefix = true; primaryKey.ChildCollection.Add(keyField); } return(primaryKey); }
/// <summary> /// 主键实体的克隆。 /// </summary> /// <returns>主键实体的副本。</returns> public override object Clone() { SqlPrimaryKey newObj = this.MemberwiseClone() as SqlPrimaryKey; return(newObj); }
/// <summary> /// 构造函数 /// </summary> public SqlStatement() : base() { PrimaryKeys = new SqlPrimaryKey(); SqlBuildingInfo = new SqlBuildingInfo(); }