Ejemplo n.º 1
0
        public void Insert0_field_path()
        {
            var aw   = new AdventureWorks();
            var path = new FieldPath();

            // creating the path in reverse should be fine
            path.Insert(0, aw.ProductCategory.DefaultField);
            path.Insert(0, aw.Products["ProductCategoryID"]);
            path.Insert(0, aw.SalesOrderDetails["ProductID"]);
        }
Ejemplo n.º 2
0
        public IEnumerable <IFieldPath> Add(Node n)
        {
            // if node is SubjectNode, add all fields (and defaults for IRelationFields)
            // if node is FieldNode with an IRelationField, add all fields for the related subject (and defaults for IRelationFields)
            // if node is FieldNode with an IField, create a path tracing back to the parent

            if (n is SubjectNode)
            {
                var fields = PathFactory.GetFields(((SubjectNode)n).Subject);
                foreach (var f in fields)
                {
                    f.Description = null; // this is bad behaviour from the FieldPathFactory
                    if (!Fields.Contains(f))
                    {
                        Fields.Add(f);
                    }
                }
                return(fields);
            }
            else if (n is FieldNode && ((FieldNode)n).Field is IRelationField)
            {
                var fields = PathFactory.GetFields((IRelationField)((FieldNode)n).Field);
                foreach (var f in fields)
                {
                    // ensure hierarchy is maintained
                    var parent = n;
                    while (parent != null && parent is FieldNode)
                    {
                        f.Insert(0, ((FieldNode)parent).Field);
                        parent = parent.Parent;
                    }
                    f.Description = null;
                    if (!Fields.Contains(f))
                    {
                        Fields.Add(f);
                    }
                }
                return(fields);
            }
            else
            {
                var path   = new FieldPath();
                var parent = n;
                while (parent != null && parent is FieldNode)
                {
                    path.Insert(0, ((FieldNode)parent).Field);
                    parent = parent.Parent;
                }
                if (!Fields.Contains(path))
                {
                    Fields.Add(path);
                }
                return(new IFieldPath[] { path });
            }
        }