예제 #1
0
        public RelationLinkType TryAddField(SingleRelationFieldMapping relateMapping)
        {
            var last = items[items.Count - 1];

            if (!Equals(relateMapping.MasterMapping, last.DataMapping))
            {
                throw new LightDataException(string.Format(SR.RelationFieldError, relateMapping.MasterMapping.ObjectType, relateMapping.FieldName));
            }
            var keys = relateMapping.GetKeyPairs();

            if (keys.Length != keyCount)
            {
                return(RelationLinkType.NoMatch);
            }
            var masters = new string[keyCount];
            var relates = new string[keyCount];

            for (var i = 0; i < keyCount; i++)
            {
                masters[i] = keys[i].MasterKey;
                relates[i] = keys[i].RelateKey;
            }
            if (!IsMatch(last.Keys, masters))
            {
                return(RelationLinkType.NoMatch);
            }
            PrevFieldPath = LastFieldPath;
            LastFieldPath = $"{last.CurrentFieldPath}.{relateMapping.FieldName}";
            var len = items.Count - 1;

            for (var i = 0; i < len; i++)
            {
                var item = items[i];
                if (Equals(relateMapping.RelateMapping, item.DataMapping))
                {
                    if (IsMatch(item.Keys, relates))
                    {
                        CycleFieldPath = item.CurrentFieldPath;
                        return(RelationLinkType.Cycle);
                    }

                    throw new LightDataException(string.Format(SR.RelationFieldKeyNotMatch, relateMapping.MasterMapping.ObjectType, relateMapping.FieldName));
                }
            }
            var relateItem = new RelationItem
            {
                DataMapping      = relateMapping.RelateMapping,
                FieldMapping     = relateMapping,
                PrevFieldPath    = PrevFieldPath,
                CurrentFieldPath = LastFieldPath,
                Keys             = relates
            };

            items.Add(relateItem);
            return(RelationLinkType.AddLink);
        }
예제 #2
0
        public RelationLinkType TryAddField(SingleRelationFieldMapping relateMapping)
        {
            RelationItem last = items[items.Count - 1];

            if (!Object.Equals(relateMapping.MasterMapping, last.DataMapping))
            {
                throw new LightDataException(string.Format(SR.RelationFieldError, relateMapping.MasterMapping.ObjectType, relateMapping.FieldName));
            }
            RelationKey[] keys = relateMapping.GetKeyPairs();
            if (keys.Length != keyCount)
            {
                return(RelationLinkType.NoMatch);
            }
            string[] masters = new string[this.keyCount];
            string[] relates = new string[this.keyCount];
            for (int i = 0; i < this.keyCount; i++)
            {
                masters[i] = keys[i].MasterKey;
                relates[i] = keys[i].RelateKey;
            }
            if (!IsMatch(last.Keys, masters))
            {
                return(RelationLinkType.NoMatch);
            }
            prevFieldPath = lastFieldPath;
            lastFieldPath = string.Format("{0}.{1}", last.CurrentFieldPath, relateMapping.FieldName);
            int len = items.Count - 1;

            for (int i = 0; i < len; i++)
            {
                RelationItem item = items[i];
                if (Object.Equals(relateMapping.RelateMapping, item.DataMapping))
                {
                    if (IsMatch(item.Keys, relates))
                    {
                        cycleFieldPath = item.CurrentFieldPath;
                        return(RelationLinkType.Cycle);
                    }
                    else
                    {
                        throw new LightDataException(string.Format(SR.RelationFieldKeyNotMatch, relateMapping.MasterMapping.ObjectType, relateMapping.FieldName));
                    }
                }
            }
            RelationItem relateItem = new RelationItem()
            {
                DataMapping      = relateMapping.RelateMapping,
                FieldMapping     = relateMapping,
                PrevFieldPath    = prevFieldPath,
                CurrentFieldPath = lastFieldPath,
                Keys             = relates
            };

            items.Add(relateItem);
            return(RelationLinkType.AddLink);
        }
예제 #3
0
        public RelationLink(SingleRelationFieldMapping rootRelationMapping, string fieldPath)
        {
            if (rootRelationMapping == null)
            {
                throw new ArgumentNullException(nameof(rootRelationMapping));
            }
            //this.rootRelationMapping = rootRelationMapping;
            var keys = rootRelationMapping.GetKeyPairs();

            keyCount = keys.Length;
            var masters = new string[keyCount];
            var relates = new string[keyCount];

            for (var i = 0; i < keyCount; i++)
            {
                masters[i] = keys[i].MasterKey;
                relates[i] = keys[i].RelateKey;
            }
            LastFieldPath = $"{fieldPath}.{rootRelationMapping.FieldName}";
            PrevFieldPath = fieldPath;
            var masterItem = new RelationItem
            {
                DataMapping  = rootRelationMapping.MasterMapping,
                FieldMapping = null,
                //PrevFieldPath = prevFieldPath,
                CurrentFieldPath = PrevFieldPath,
                Keys             = masters
            };

            var relateItem = new RelationItem
            {
                DataMapping      = rootRelationMapping.RelateMapping,
                FieldMapping     = rootRelationMapping,
                PrevFieldPath    = PrevFieldPath,
                CurrentFieldPath = LastFieldPath,
                Keys             = relates
            };

            items.Add(masterItem);
            items.Add(relateItem);
        }
예제 #4
0
        public RelationLink(SingleRelationFieldMapping rootRelationMapping, string fieldPath)
        {
            if (rootRelationMapping == null)
            {
                throw new ArgumentNullException(nameof(rootRelationMapping));
            }
            //this.rootRelationMapping = rootRelationMapping;
            RelationKey[] keys = rootRelationMapping.GetKeyPairs();
            this.keyCount = keys.Length;
            string[] masters = new string[this.keyCount];
            string[] relates = new string[this.keyCount];
            for (int i = 0; i < this.keyCount; i++)
            {
                masters[i] = keys[i].MasterKey;
                relates[i] = keys[i].RelateKey;
            }
            lastFieldPath = string.Format("{0}.{1}", fieldPath, rootRelationMapping.FieldName);
            prevFieldPath = fieldPath;
            RelationItem masterItem = new RelationItem()
            {
                DataMapping  = rootRelationMapping.MasterMapping,
                FieldMapping = null,
                //PrevFieldPath = prevFieldPath,
                CurrentFieldPath = prevFieldPath,
                Keys             = masters
            };

            RelationItem relateItem = new RelationItem()
            {
                DataMapping      = rootRelationMapping.RelateMapping,
                FieldMapping     = rootRelationMapping,
                PrevFieldPath    = prevFieldPath,
                CurrentFieldPath = lastFieldPath,
                Keys             = relates
            };

            items.Add(masterItem);
            items.Add(relateItem);
        }