Ejemplo n.º 1
0
        protected List <MappedProperty> CopyProperties(List <MappedProperty> properties)
        {
            List <MappedProperty> list = new List <MappedProperty>();

            foreach (MappedProperty prop in properties)
            {
                MappedProperty copy = prop.Copy();
                if (prop.IsComplexProperty)
                {
                    copy.ChildProperties = CopyProperties(prop.ChildProperties);
                }
                list.Add(copy);
            }

            return(list);
        }
Ejemplo n.º 2
0
        public List <MappedProperty> OrderFlatBySelectedProperties(List <MappedProperty> properties, List <string> includeProperties)
        {
            if (includeProperties.Count == 0)
            {
                return(properties);
            }

            List <MappedProperty> result = new List <MappedProperty>();

            foreach (string includedPropName in includeProperties)
            {
                MappedProperty mappedProperty = properties.First(x => x.EfDefaultName == includedPropName);
                result.Add(mappedProperty);
            }

            return(result);
        }
Ejemplo n.º 3
0
        //Filtering and ordering
        public List <MappedProperty> FilterProperties(List <MappedProperty> properties, bool hasOtherConditions
                                                      , List <string> includeProperties, List <string> excludeProperties
                                                      , bool excludeAllByDefault, ExcludeOptions includeDbGeneratedProperties)
        {
            List <MappedProperty> selectedProperties;

            if (includeProperties.Count > 0 || hasOtherConditions)
            {
                selectedProperties = properties.Where(
                    pr => pr.IsComplexProperty ||
                    includeProperties.Contains(pr.EfDefaultName))
                                     .ToList();
            }
            else if (excludeProperties.Count > 0)
            {
                selectedProperties = properties.Where(
                    pr => pr.IsComplexProperty ||
                    !excludeProperties.Contains(pr.EfDefaultName))
                                     .ToList();
            }
            else if (excludeAllByDefault)
            {
                selectedProperties = new List <MappedProperty>();

                if (includeDbGeneratedProperties == ExcludeOptions.Include)
                {
                    List <string> generatedProps = _context.GetDatabaseGeneratedProperties(_rootEntityType);
                    selectedProperties = properties
                                         .Where(x => generatedProps.Contains(x.EfMappedName))
                                         .ToList();
                }
            }
            else //include all by default
            {
                selectedProperties = properties;

                if (includeDbGeneratedProperties == ExcludeOptions.Exclude)
                {
                    List <string> generatedProps = _context.GetDatabaseGeneratedProperties(_rootEntityType);
                    selectedProperties = selectedProperties
                                         .Where(x => !generatedProps.Contains(x.EfMappedName))
                                         .ToList();
                }
            }

            //exclude properties that are not mapped to any column
            selectedProperties = selectedProperties.Where(
                pr => pr.IsComplexProperty ||
                pr.EfMappedName != null)
                                 .ToList();

            for (int i = 0; i < selectedProperties.Count; i++)
            {
                if (selectedProperties[i].IsComplexProperty)
                {
                    MappedProperty copy = selectedProperties[i].Copy();
                    copy.ChildProperties = FilterProperties(selectedProperties[i].ChildProperties, hasOtherConditions
                                                            , includeProperties, excludeProperties, excludeAllByDefault, includeDbGeneratedProperties);
                    selectedProperties[i] = copy;
                }
            }

            return(selectedProperties);
        }