/// <summary>
        /// 构造左连接SQL
        /// </summary>
        /// <param name="sql">Select语句</param>
        /// <param name="association">关联</param>
        private void BuildLeftJoin(SelectSqlStatement sql, InternalAssociation association, SqlBuildingContext context)
        {
            LeftJoinItem leftJoin = new LeftJoinItem();
            leftJoin.LeftJoinTable = association.LocatedTable;
            foreach (var item in association.Association.Items)
            {
                SqlTable srcElelemtTable = association.LocatedTable;
                var srcElement = association.LocatedNode.Elements.FirstOrDefault(i => i.ID == item.SourceElementID);
                var targetElement = association.AssociatedCoNode.Elements.FirstOrDefault(i => i.ID == item.TargetElementID);


                var leftCol = association.LocatedDataObject.Columns.FirstOrDefault(i => i.ID == srcElement.DataColumnID);
                var rightCol = association.AssociatedDataObject.Columns.FirstOrDefault(i => i.ID == targetElement.DataColumnID);

                JoinConditionItem joinItem = new JoinConditionItem();
                joinItem.LeftField.Table = srcElelemtTable;
                joinItem.LeftField.FieldName = leftCol.ColumnName;
                joinItem.LeftField.IsUseFieldPrefix = true;
                joinItem.RightField.Table = association.AssociatedTable;
                joinItem.RightField.FieldName = rightCol.ColumnName;
                joinItem.RightField.IsUseFieldPrefix = true;
                leftJoin.ChildCollection.Add(joinItem);
            }

            //关联上的条件
            leftJoin.AdditionalCondition = this.ParseCondition(association);            

            sql.MainFromItem.ChildCollection.Add(leftJoin);
        }
Ejemplo n.º 2
0
        public override void ToXml(SqlElement sqlElement, XmlElement xmlParent)
        {
            base.ToXml(sqlElement, xmlParent);

            LeftJoinItem leftJoinItem = sqlElement as LeftJoinItem;

            XmlElement xmlLeftJoinTable = SerializerUtil.AddElement(xmlParent, LEFTJOINTABLE);

            leftJoinItem.LeftJoinTable.ToXml(leftJoinItem.LeftJoinTable, xmlLeftJoinTable);

            XmlElement xmlAddtionalCondition = SerializerUtil.AddElement(xmlParent, ADDITIONALCONDITION, leftJoinItem.AdditionalCondition);
        }
Ejemplo n.º 3
0
        public override void FromXml(SqlElement sqlElement, XmlElement xmlParent, XmlNamespaceManager xnm)
        {
            base.FromXml(sqlElement, xmlParent, xnm);

            LeftJoinItem leftJoinItem = sqlElement as LeftJoinItem;
            ParserUtil   util         = new ParserUtil(xnm);

            XmlElement xmlLeftJoinTable = util.Child(xmlParent, LEFTJOINTABLE);

            leftJoinItem.LeftJoinTable.FromXml(leftJoinItem.LeftJoinTable, xmlLeftJoinTable, xnm);

            XmlElement xmlAddtionalCondition = util.Child(xmlParent, ADDITIONALCONDITION);

            leftJoinItem.AdditionalCondition = xmlAddtionalCondition.InnerText;
        }