Exemplo n.º 1
0
        private IEnumerable <DynamicFilterDefinition> FindFiltersForEntitySet(ReadOnlyMetadataCollection <MetadataProperty> metadataProperties)
        {
            var configuration = metadataProperties.FirstOrDefault(p => p.Name == "Configuration")?.Value;

            if (configuration == null)
            {
                return(new List <DynamicFilterDefinition>());
            }

            //  The "Annotations" property will not exist if this is a navigation property (because configuration
            //  is a NavigationPropertyConfiguration object not an EntityTypeConfiguration object.
            //  That happens if we use the entry.Load() command to load a child collection.  See issue #71.
            var annotations = configuration.GetType().GetProperty("Annotations")?.GetValue(configuration, null) as Dictionary <string, object>;

            if (annotations == null)
            {
                return(new List <DynamicFilterDefinition>());
            }

            var filterList = annotations.Select(a => a.Value as DynamicFilterDefinition).Where(a => a != null).ToList();

            //  Note: Prior to the switch to use CSpace (which was done to allow filters on navigation properties),
            //  we had to remove filters that exist in base EntitySets to this entity to fix issues with
            //  Table-per-Type inheritance (issue #32).  In CSpace none of that is necessary since we are working
            //  with the actual c# models now (in CSpace) so we always have the correct filters and access to all
            //  the inherited properties that we need.

            return(filterList);
        }
        private IEnumerable <DynamicFilterDefinition> FindFiltersForEntitySet(ReadOnlyMetadataCollection <MetadataProperty> metadataProperties, bool isMainEntity)
        {
            var configuration = metadataProperties.FirstOrDefault(p => p.Name == "Configuration")?.Value;

            if (configuration == null)
            {
                return(new List <DynamicFilterDefinition>());
            }

            //  The "Annotations" property will not exist if this is a navigation property (because configuration
            //  is a NavigationPropertyConfiguration object not an EntityTypeConfiguration object.
            //  That happens if we use the entry.Load() command to load a child collection.  See issue #71.
            var annotations = configuration.GetType().GetProperty("Annotations")?.GetValue(configuration, null) as Dictionary <string, object>;

            if (annotations == null)
            {
                return(new List <DynamicFilterDefinition>());
            }

            var filterList = annotations.Select(a => a.Value as DynamicFilterDefinition)
                             .Where(a => (a != null) && (isMainEntity || a.Options.ApplyToChildProperties))
                             .Where(a => isMainEntity || (a.Options.ApplyRecursively || !_AppliedFilters.Contains(a.FilterName)))
                             .ToList();

            //  Note: Prior to the switch to use CSpace (which was done to allow filters on navigation properties),
            //  we had to remove filters that exist in base EntitySets to this entity to fix issues with
            //  Table-per-Type inheritance (issue #32).  In CSpace none of that is necessary since we are working
            //  with the actual c# models now (in CSpace) so we always have the correct filters and access to all
            //  the inherited properties that we need.

#if DEBUG_VISITS
            System.Diagnostics.Debug.Print("  Found {0} filters for Type {1}; isMainEntity={2}", filterList.Count, metadataProperties.FirstOrDefault(p => p.Name == "Name")?.Value, isMainEntity);
#endif
            return(filterList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Example for traversing a model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TraverseButton_Click(object sender, EventArgs e)
        {
            const int indent = 20;

            ReadOnlyMetadataCollection <NavigationProperty> metadata = EntityFrameworkHelper.GetNavigationProperties <Order, NorthContext>();

            var nameParts = metadata.FirstOrDefault().DeclaringType.FullName.Split('.');

            Debug.WriteLine($"namespace: {nameParts[0]}");
            Debug.WriteLine($"    class: {nameParts[1]}");

            Debug.WriteLine("");

            Debug.WriteLine("navigation model names");

            var navigationPropertyNames = metadata.Select(np => np.Name).ToList();


            foreach (var name in navigationPropertyNames)
            {
                Debug.WriteLine($"{name,indent}");
            }

            Debug.WriteLine("");
            Debug.WriteLine("RelationshipType names");
            var relationNames = metadata.Select(np => np.RelationshipType.Name).ToList();

            foreach (var relationName in relationNames)
            {
                Debug.WriteLine($"{relationName,indent}");
            }


            MessageBox.Show("See output window");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get column details
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public List <EntityColumn> GetColumnInformation(string tableName)
        {
            var list = new List <EntityColumn>();

            /*
             * Checking FullName differs between code first and edmx
             * code first: CodeFirstDatabaseSchema
             * edmx: store
             */
            var metaData = (
                _entityTypesData.Where(entityType => entityType.FullName == $"{EnitityModelName}.{tableName}")
                .Select(entityTypesData => entityTypesData.DeclaredProperties)).ToList();


            EntityType entityType1 = _entityTypesData.ToList().Where(item => item.Name == tableName).FirstOrDefault();
            ReadOnlyMetadataCollection <EdmProperty> props = entityType1.KeyProperties;

            foreach (ReadOnlyMetadataCollection <EdmProperty> prop in metaData)
            {
                foreach (var itemEdmProperty in prop.ToList())
                {
                    bool primaryKey = false;

                    if (props != null)
                    {
                        primaryKey = props.FirstOrDefault(item => item.Name == itemEdmProperty.Name) != null;
                    }

                    list.Add(new EntityColumn()
                    {
                        Name     = itemEdmProperty.Name,
                        Type     = itemEdmProperty.PrimitiveType.ClrEquivalentType,
                        TypeName = itemEdmProperty.TypeName,
                        Key      = primaryKey
                    });
                }
            }

            return(list);
        }
        private IEnumerable<DynamicFilterDefinition> FindFiltersForEntitySet(ReadOnlyMetadataCollection<MetadataProperty> metadataProperties)
        {
            var configuration = metadataProperties.FirstOrDefault(p => p.Name == "Configuration")?.Value;
            if (configuration == null)
                return new List<DynamicFilterDefinition>();

            //  The "Annotations" property will not exist if this is a navigation property (because configuration
            //  is a NavigationPropertyConfiguration object not an EntityTypeConfiguration object.
            //  That happens if we use the entry.Load() command to load a child collection.  See issue #71.
            var annotations = configuration.GetType().GetProperty("Annotations")?.GetValue(configuration, null) as Dictionary<string, object>;
            if (annotations == null)
                return new List<DynamicFilterDefinition>();

            var filterList = annotations.Select(a => a.Value as DynamicFilterDefinition).Where(a => a != null).ToList();

            //  Note: Prior to the switch to use CSpace (which was done to allow filters on navigation properties),
            //  we had to remove filters that exist in base EntitySets to this entity to fix issues with 
            //  Table-per-Type inheritance (issue #32).  In CSpace none of that is necessary since we are working
            //  with the actual c# models now (in CSpace) so we always have the correct filters and access to all
            //  the inherited properties that we need.

            return filterList;
        }