Example #1
0
        private void LoadJoinRelate()
        {
            LoadEntityMapping(RootMapping, null);
            var joinSelector = new JoinSelector();
            var items        = new List <RelationItem>();
            // var relationItemDict = new Dictionary<string, RelationItem>();
            var tIndex = 0;

            foreach (var link in linkList)
            {
                var sItems = link.GetRelationItems();
                foreach (var item in sItems)
                {
                    if (!items.Contains(item))
                    {
                        if (item.FieldMapping == null && tIndex != 0)
                        {
                            continue;
                        }
                        item.AliasName = "T" + tIndex;
                        tIndex++;
                        items.Add(item);
                        // relationItemDict.Add(item.CurrentFieldPath, item);
                    }
                }
            }

            var rootItem = items[0];

            mapDict.Add(items[0].CurrentFieldPath, items[0]);
            var rootInfoList = new List <DataFieldInfo>();

            foreach (var field in RootMapping.DataEntityFields)
            {
                var info      = new DataFieldInfo(field);
                var aliasName = $"{rootItem.AliasName}_{info.FieldName}";
                var alias     = new AliasDataFieldInfo(info, aliasName, rootItem.AliasName);
                joinSelector.SetAliasDataField(alias);
                rootInfoList.Add(alias);
                fieldInfoDict.Add($"{items[0].CurrentFieldPath}.{field.IndexName}", alias);
            }
            tableInfoDict.Add(items[0].CurrentFieldPath, rootInfoList.ToArray());

            for (var i = 1; i < items.Count; i++)
            {
                var mItem = items[i];
                mapDict.Add(mItem.CurrentFieldPath, mItem);
                var fieldMapping = mItem.FieldMapping;
                var mapping      = fieldMapping.RelateMapping;
                DataFieldExpression expression = null;

                var rItem  = mapDict[mItem.PrevFieldPath];
                var mAlias = rItem.AliasName;
                var rAlias = mItem.AliasName;

                var relations = fieldMapping.CreateDataFieldInfoRelations(mAlias, rAlias);
                foreach (var relation in relations)
                {
                    var mInfo         = relation.MasterInfo;
                    var rInfo         = relation.RelateInfo;
                    var keyExpression = new DataFieldOnMatchExpression(mInfo, rInfo, QueryPredicate.Eq);
                    expression = DataFieldExpression.And(expression, keyExpression);
                }
                var infoList = new List <DataFieldInfo>();
                foreach (var field in mapping.DataEntityFields)
                {
                    var info      = new DataFieldInfo(field);
                    var aliasName = $"{rAlias}_{info.FieldName}";
                    var alias     = new AliasDataFieldInfo(info, aliasName, rAlias);
                    joinSelector.SetAliasDataField(alias);
                    infoList.Add(alias);
                    fieldInfoDict.Add($"{mItem.CurrentFieldPath}.{field.Name}", alias);
                }
                tableInfoDict.Add(mItem.CurrentFieldPath, infoList.ToArray());

                var connect = new JoinConnect(JoinType.LeftJoin, expression);
                var model   = new EntityJoinModel(mapping, rAlias, connect, null, null, JoinSetting.None);
                selector = joinSelector;
                models.Add(model);
            }
        }
Example #2
0
        void LoadJoinRelate()
        {
            LoadEntityMapping(this.rootMapping, null);
            JoinSelector        joinSelector = new JoinSelector();
            List <RelationItem> items        = new List <RelationItem>();
            Dictionary <string, RelationItem> relationItemDict = new Dictionary <string, RelationItem>();
            int tindex = 0;

            foreach (RelationLink link in linkList)
            {
                RelationItem[] sitems = link.GetRelationItems();
                foreach (RelationItem item in sitems)
                {
                    if (!items.Contains(item))
                    {
                        if (item.FieldMapping == null && tindex != 0)
                        {
                            continue;
                        }
                        item.AliasName = "T" + tindex;
                        tindex++;
                        items.Add(item);
                        relationItemDict.Add(item.CurrentFieldPath, item);
                    }
                }
            }
            //if (this.rootMapping != items [0].DataMapping) {
            //	throw new LightDataException (RE.RelationMapEntityMappingError);
            //}

            RelationItem rootItem = items[0];

            mapDict.Add(items[0].CurrentFieldPath, items[0]);
            List <DataFieldInfo> rootInfoList = new List <DataFieldInfo>();

            foreach (DataFieldMapping field in this.rootMapping.DataEntityFields)
            {
                DataFieldInfo      info      = new DataFieldInfo(field);
                string             aliasName = string.Format("{0}_{1}", rootItem.AliasName, info.FieldName);
                AliasDataFieldInfo alias     = new AliasDataFieldInfo(info, aliasName, rootItem.AliasName);
                //alias.AliasTablesName = rootItem.AliasName;
                joinSelector.SetAliasDataField(alias);
                rootInfoList.Add(alias);
                fieldInfoDict.Add(string.Format("{0}.{1}", items[0].CurrentFieldPath, field.IndexName), alias);
            }
            tableInfoDict.Add(items[0].CurrentFieldPath, rootInfoList.ToArray());

            for (int i = 1; i < items.Count; i++)
            {
                RelationItem mitem = items[i];
                mapDict.Add(mitem.CurrentFieldPath, mitem);
                SingleRelationFieldMapping fieldMapping = mitem.FieldMapping;
                DataEntityMapping          mapping      = fieldMapping.RelateMapping;
                DataFieldExpression        expression   = null;
                //DataFieldInfoRelation [] relations = fieldMapping.GetDataFieldInfoRelations ();

                RelationItem ritem  = mapDict[mitem.PrevFieldPath];
                string       malias = ritem.AliasName;
                string       ralias = mitem.AliasName;

                DataFieldInfoRelation[] relations = fieldMapping.CreateDataFieldInfoRelations(malias, ralias);
                foreach (DataFieldInfoRelation relation in relations)
                {
                    DataFieldInfo minfo = relation.MasterInfo;
                    //minfo.AliasTableName = malias;
                    DataFieldInfo rinfo = relation.RelateInfo;
                    //rinfo.AliasTableName = ralias;
                    DataFieldMatchExpression keyExpression = new DataFieldMatchExpression(minfo, rinfo, QueryPredicate.Eq);
                    expression = DataFieldExpression.And(expression, keyExpression);
                    //expression = DataFieldExpression.And (expression, minfo == rinfo);
                }
                List <DataFieldInfo> infoList = new List <DataFieldInfo>();
                foreach (DataFieldMapping field in mapping.DataEntityFields)
                {
                    DataFieldInfo      info      = new DataFieldInfo(field);
                    string             aliasName = string.Format("{0}_{1}", ralias, info.FieldName);
                    AliasDataFieldInfo alias     = new AliasDataFieldInfo(info, aliasName, ralias);
                    //alias.AliasTableName = ralias;
                    joinSelector.SetAliasDataField(alias);
                    infoList.Add(alias);
                    fieldInfoDict.Add(string.Format("{0}.{1}", mitem.CurrentFieldPath, field.Name), alias);
                }
                tableInfoDict.Add(mitem.CurrentFieldPath, infoList.ToArray());

                JoinConnect     connect = new JoinConnect(JoinType.LeftJoin, expression);
                EntityJoinModel model   = new EntityJoinModel(mapping, ralias, connect, null, null, JoinSetting.None);
                this.selector = joinSelector;
                this.models.Add(model);
            }
        }