Ejemplo n.º 1
0
        /// <summary>
        /// İlgili manager'ın entity'lerine ulaşmak için gereken path'i, parametre kullanarak oluşturmalı.
        /// </summary>
        /// <param name="p">Parametre</param>
        /// <param name="path">PathElement, rootPath değil. Bu metod başka manager'dan çağırıldığından, rootPath başka manager'da olacaktır. Bu metod pathElement üretir.</param>
        /// <returns></returns>
        public IPrefetchPathElement2 GetPathElement(TParameter p, IPrefetchPathElement2 path)
        {
            IPredicateExpression filterPredicateExpression = new PredicateExpression();

            //Filtering
            PrepareFilter(p, ref filterPredicateExpression);
            path.Filter = filterPredicateExpression;

            //Relations
            //PrepareRelations(p, path.FilterRelations);

            //Sort
            ISortExpression sortExpression = new SortExpression();

            PrepareSortExpression(p, ref sortExpression);
            path.Sorter = sortExpression;

            //SubPaths
            var subPath = new PrefetchPath2(EntityTypeEnumValue);

            if (p.PathsFunc != null)
            {
                p.PathsFunc.Invoke(subPath);
            }
            //PrepareSubPaths(p, ref subPath);
            path.SubPath = subPath;

            return(path);
        }
        public void Add(IPrefetchPathElement2 path, EntityClonerBase cloner)
        {
            if (!_requireCloner) throw new InvalidOperationException(
                "Adding a relation for ignoring can not take a cloner.");

            _relations[path] = cloner;
        }
Ejemplo n.º 3
0
        private static void PrintSchema(IPrefetchPathElement2 pathElement, string rootEntityName)
        {
            if (pathElement != null)
            {
                string indentation = "".PadLeft(pathElement.GraphLevel);
                string basePropertyName = pathElement.PropertyName;

                IEntityFactory2 relatedEntityFactory = pathElement.EntityFactoryToUse;

                // This is what LLBL does internally.
                if (relatedEntityFactory == null)
                {
                    relatedEntityFactory = pathElement.RetrievalCollection.EntityFactoryToUse;
                }

                string relatedEntityName = relatedEntityFactory.ForEntityName;

                System.Console.Out.WriteLine(indentation + rootEntityName + "." + basePropertyName + " -> " + relatedEntityName);

                if (pathElement.SubPath != null)
                {
                    PrintEntityFields(relatedEntityFactory.Create(), pathElement.GraphLevel + 1);
                    PrintSchema(pathElement.SubPath, relatedEntityFactory.ForEntityName);
                }
            }
        }
Ejemplo n.º 4
0
        internal static IPrefetchPath2 ConvertStringToPrefetchPath(EntityType entityType, string prefetchStr, string selectStr)
        {
            if (string.IsNullOrWhiteSpace(prefetchStr))
            {
                return(null);
            }

            // Break up the selectStr into a dictionary of keys and values
            // where the key is the path (i.e.: products.supplier)
            // and the value is the field name (i.e.: companyname)
            var prefetchFieldKeysAndNames = (selectStr ?? "")
                                            .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                            .Where(s => s.IndexOf('.') > 0)
                                            .Select(s => s.Trim('.').ToLowerInvariant());
            var prefetchFieldNamesDictionary = new Dictionary <string, List <string> >();

            foreach (var s in prefetchFieldKeysAndNames)
            {
                var key   = s.Substring(0, s.LastIndexOf('.'));
                var value = s.Substring(s.LastIndexOf('.') + 1);
                if (prefetchFieldNamesDictionary.ContainsKey(key))
                {
                    prefetchFieldNamesDictionary[key].AddIfNotExists(value);
                }
                else
                {
                    prefetchFieldNamesDictionary.Add(key, new List <string>(new[] { value }));
                }
            }

            var prefetchStrs = prefetchStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var nodeLeaves   =
                prefetchStrs.Select(n => n.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries)).ToArray();
            var rootNode = new PrefetchElementStringRepresentation {
                Name = "root", MaxNumberOfItemsToReturn = 0
            };

            foreach (var nodeLeaf in nodeLeaves)
            {
                BuildTreeNode(rootNode, nodeLeaf, 0);
            }

            var prefetch = new PrefetchPath2(entityType);

            foreach (var prefetchRepresentation in rootNode.Children)
            {
                ExcludeIncludeFieldsList prefetchPathElementIncludeFieldList;
                IPrefetchPathElement2    prefetchPathElement =
                    ConvertPrefetchRepresentationToPrefetchPathElement(entityType, prefetchRepresentation,
                                                                       prefetchFieldNamesDictionary,
                                                                       prefetchRepresentation.Name.ToLowerInvariant(),
                                                                       out prefetchPathElementIncludeFieldList);
                if (prefetchPathElement != null)
                {
                    prefetch.Add(prefetchPathElement, prefetchPathElementIncludeFieldList);
                }
            }
            return(prefetch.Count > 0 ? prefetch : null);
        }
Ejemplo n.º 5
0
        private static IPrefetchPathElement2 ConvertPrefetchRepresentationToPrefetchPathElement(EntityType parentEntityType,
                                                                                                PrefetchElementStringRepresentation
                                                                                                prefetchRepresentation,
                                                                                                Dictionary
                                                                                                <string, List <string> >
                                                                                                prefetchFieldNamesDictionary,
                                                                                                string fieldNamesKey,
                                                                                                out ExcludeIncludeFieldsList
                                                                                                includeFieldList)
        {
            includeFieldList = null;

            if (prefetchRepresentation == null)
            {
                return(null);
            }

            var includeMap = GetEntityTypeIncludeMap(parentEntityType);

            IPrefetchPathElement2 newElement = null;
            var rr =
                includeMap.FirstOrDefault(
                    rm => rm.Key.Equals(prefetchRepresentation.Name, StringComparison.InvariantCultureIgnoreCase));

            if (!rr.Equals(default(KeyValuePair <string, IPrefetchPathElement2>)))
            {
                newElement = rr.Value;

                foreach (var childRepresentation in prefetchRepresentation.Children)
                {
                    ExcludeIncludeFieldsList subElementIncludeFieldList;
                    var subElement =
                        ConvertPrefetchRepresentationToPrefetchPathElement((EntityType)newElement.ToFetchEntityType,
                                                                           childRepresentation,
                                                                           prefetchFieldNamesDictionary,
                                                                           string.Concat(fieldNamesKey, ".",
                                                                                         childRepresentation.Name
                                                                                         .ToLowerInvariant
                                                                                             ()),
                                                                           out subElementIncludeFieldList);
                    if (subElement != null)
                    {
                        newElement.SubPath.Add(subElement, subElementIncludeFieldList);
                    }
                }
            }

            if (newElement != null)
            {
                // Determin if there is a max amount of records to return for this prefetch element
                if (newElement.MaxAmountOfItemsToReturn < prefetchRepresentation.MaxNumberOfItemsToReturn)
                {
                    newElement.MaxAmountOfItemsToReturn = prefetchRepresentation.MaxNumberOfItemsToReturn;
                }

                // Determine if there are field name restrictions applied to the prefetched item
                if (prefetchFieldNamesDictionary.ContainsKey(fieldNamesKey))
                {
                    includeFieldList = ConvertEntityTypeFieldNamesToExcludedIncludedFields(
                        (EntityType)newElement.ToFetchEntityType, prefetchFieldNamesDictionary[fieldNamesKey]);
                }
            }

            return(newElement);
        }
Ejemplo n.º 6
0
 public static IPrefetchPathElement2 WithMaxNumberOfItems(this IPrefetchPathElement2 path, int maxNumber)
 {
     path.MaxAmountOfItemsToReturn = maxNumber;
     return(path);
 }