Beispiel #1
0
        public RelationLink Fork()
        {
            RelationLink link = new RelationLink();

            link.cycleItem     = cycleItem;
            link.lastFieldPath = lastFieldPath;
            link.keyCount      = keyCount;
            link.items         = new List <RelationItem>(items);
            return(link);
        }
Beispiel #2
0
        public RelationLink Fork()
        {
            var link = new RelationLink
            {
                CycleItem     = CycleItem,
                LastFieldPath = LastFieldPath,
                keyCount      = keyCount,
                items         = new List <RelationItem>(items)
            };

            return(link);
        }
Beispiel #3
0
        private void LoadEntityMapping(DataEntityMapping mapping, RelationLink link)
        {
            var path = link != null ? link.LastFieldPath : string.Empty;

            foreach (var relateFieldMapping in mapping.SingleJoinTableRelationFieldMappings)
            {
                relateFieldMapping.InitialRelation();
                var add = false;
                if (link == null)
                {
                    var mLink = new RelationLink(relateFieldMapping, string.Empty);
                    linkList.Add(mLink);
                    LoadEntityMapping(relateFieldMapping.RelateMapping, mLink);
                    add = true;
                }
                else
                {
                    var fLink    = link.Fork();
                    var linkType = fLink.TryAddField(relateFieldMapping);
                    if (linkType == RelationLinkType.NoMatch)
                    {
                        //新开关系链分支加入链集合
                        var mLink = new RelationLink(relateFieldMapping, link.LastFieldPath);
                        linkList.Add(mLink);
                        LoadEntityMapping(relateFieldMapping.RelateMapping, mLink);
                        add = true;
                    }
                    else if (linkType == RelationLinkType.AddLink)
                    {
                        //将原关系链追加后再加入链集合
                        linkList.Add(fLink);
                        LoadEntityMapping(relateFieldMapping.RelateMapping, fLink);
                        add = true;
                    }
                    else
                    {
                        //原关系链已能形成闭环,不需修改
                        cycleDict.Add(fLink.LastFieldPath, fLink.CycleFieldPath);
                    }
                }
                if (add)
                {
                    var kps     = relateFieldMapping.GetKeyPairs();
                    var relates = new string[kps.Length];
                    for (var i = 0; i < kps.Length; i++)
                    {
                        relates[i] = $"{path}.{relateFieldMapping.FieldName}.{kps[i].RelateKey}";
                    }
                    var relate = $"{path}.{relateFieldMapping.FieldName}";
                    singleDict[relate] = relates;
                }
            }
            foreach (var collectFieldMapping in mapping.CollectionRelationFieldMappings)
            {
                var kps     = collectFieldMapping.GetKeyPairs();
                var masters = new string[kps.Length];
                for (var i = 0; i < kps.Length; i++)
                {
                    masters[i] = $"{path}.{kps[i].MasterKey}";
                }
                var collectField = $"{path}.{collectFieldMapping.FieldName}";
                collectionDict[collectField] = masters;
            }
        }
Beispiel #4
0
        void LoadEntityMapping(DataEntityMapping mapping, RelationLink link)
        {
            string path = link != null ? link.LastFieldPath : string.Empty;

            foreach (SingleRelationFieldMapping relateFieldMapping in mapping.SingleJoinTableRelationFieldMappings)
            {
                relateFieldMapping.InitialRelation();
                bool add = false;
                if (link == null)
                {
                    RelationLink mlink = new RelationLink(relateFieldMapping, string.Empty);
                    linkList.Add(mlink);
                    LoadEntityMapping(relateFieldMapping.RelateMapping, mlink);
                    add = true;
                }
                else
                {
                    RelationLink     flink    = link.Fork();
                    RelationLinkType linkType = flink.TryAddField(relateFieldMapping);
                    if (linkType == RelationLinkType.NoMatch)
                    {
                        //新开关系链分支加入链集合
                        RelationLink mlink = new RelationLink(relateFieldMapping, link.LastFieldPath);
                        linkList.Add(mlink);
                        LoadEntityMapping(relateFieldMapping.RelateMapping, mlink);
                        add = true;
                    }
                    else if (linkType == RelationLinkType.AddLink)
                    {
                        //将原关系链追加后再加入链集合
                        linkList.Add(flink);
                        LoadEntityMapping(relateFieldMapping.RelateMapping, flink);
                        add = true;
                    }
                    else
                    {
                        //原关系链已能形成闭环,不需修改
                        cycleDict.Add(flink.LastFieldPath, flink.CycleFieldPath);
                    }
                }
                if (add)
                {
                    RelationKey[] kps     = relateFieldMapping.GetKeyPairs();
                    string[]      relates = new string[kps.Length];
                    for (int i = 0; i < kps.Length; i++)
                    {
                        relates[i] = string.Format("{0}.{1}.{2}", path, relateFieldMapping.FieldName, kps[i].RelateKey);
                    }
                    string relate = string.Format("{0}.{1}", path, relateFieldMapping.FieldName);
                    singleDict[relate] = relates;
                }
            }
            foreach (CollectionRelationFieldMapping collectFieldMapping in mapping.CollectionRelationFieldMappings)
            {
                RelationKey[] kps     = collectFieldMapping.GetKeyPairs();
                string[]      masters = new string[kps.Length];
                for (int i = 0; i < kps.Length; i++)
                {
                    masters[i] = string.Format("{0}.{1}", path, kps[i].MasterKey);
                }
                string collectField = string.Format("{0}.{1}", path, collectFieldMapping.FieldName);
                collectionDict[collectField] = masters;
            }
        }