/// <summary>
 /// 构造Insert语句中的插入字段
 /// </summary>
 /// <param name="sql">Insert语句</param>
 /// <param name="context">SQL构造上下文</param>
 protected void HandlingInsertFields(InsertSqlStatement sql, SqlBuildingContext context)
 {
     foreach (var col in context.DataObject.Columns)
     {
         sql.InsertFields.ChildCollection.Add(new InsertField()
         {
             FieldName       = col.ColumnName,
             IsUseVarBinding = true
         });
     }
 }
        /// <summary>
        /// 处理带数据的元素
        /// </summary>
        /// <param name="sql">Insert语句</param>
        /// <param name="context">策略的上下文</param>
        protected void HandlingFieldsAddData(InsertSqlStatement sql, SqlBuildingContext context)
        {
            var excludeField = new List <InsertField>();

            foreach (InsertField insertField in sql.InsertFields.ChildCollection)
            {
                var insertCol = context.DataObject.Columns.FirstOrDefault(i => i.ColumnName == insertField.FieldName);
                if (insertCol == null)
                {
                    throw new Exception("Cannot find column: " + insertField.FieldName);
                }
                var insertElement = context.Node.Elements.FirstOrDefault(i => i.DataColumnID == insertCol.ID);
                if (insertElement == null)
                {
                    throw new Exception("Cannot find DomainObjectElement, DataColumnID: " + insertCol.ID);
                }
                if (!context.DataContext.GetCurrentDataContextItem(context.Node.ID).Data.ContainsKey(insertElement.ID))
                {
                    excludeField.Add(insertField);
                    continue;
                }

                var fieldValue = new InsertValue();

                fieldValue.DataType = Convert.ToInt32(insertElement.DataType);
                var value = context.DataContext.GetCurrentDataContextItem(context.Node.ID).Data[insertElement.ID];
                fieldValue.Value = ElementValueWrapper.ConvertElementValue(insertElement, value);
                sql.InsertValues.ChildCollection.Add(fieldValue);
            }

            if (excludeField != null && excludeField.Count > 0)
            {
                foreach (var field in excludeField)
                {
                    sql.InsertFields.ChildCollection.Remove(field);
                }
            }

            if (sql.InsertFields.ChildCollection.Count == 0)
            {
                throw new Exception(string.Format("数据访问服务-插入的字段为空, DomainModel:{0}, DomainObject:{1} ",
                                                  context.CommonObject.ID, context.Node.ID));
            }
            if (sql.InsertFields.ChildCollection.Count != sql.InsertValues.ChildCollection.Count)
            {
                throw new Exception(string.Format("数据访问服务-插入的字段与值个数不匹配, DomainModel:{0}, DomainObject:{1} ",
                                                  context.CommonObject.ID, context.Node.ID));
            }
        }