Ejemplo n.º 1
0
        public EntityInfo(MetadataModel model, EntityMetadata entity)
        {
            EntityMetadata = entity;

            // RootType ermitteln
            var root = entity;

            while (root.BaseEntity != null)
            {
                root = root.BaseEntity;
            }

            RootType = root;

            var scalarBuilder     = ImmutableList.CreateBuilder <ScalarProperty>();
            var navigationBuilder = ImmutableList.CreateBuilder <NavigationPropertyMetadata>();
            var reverseBuilder    = ImmutableList.CreateBuilder <NavigationPropertyMetadata>();
            var foreignKeyBuilder = ImmutableDictionary.CreateBuilder <ScalarProperty, NavigationPropertyMetadata>();

            // Properties befüllen
            FillProperties(model, entity, scalarBuilder, navigationBuilder, reverseBuilder, foreignKeyBuilder);

            NavigationProperties        = navigationBuilder.ToImmutable();
            ReverseNavigationProperties = reverseBuilder.ToImmutable();
            ScalarProperties            = scalarBuilder.ToImmutable();
            ForeignKeyProperties        = foreignKeyBuilder.ToImmutable();

            _mergeByKeyDelegate = GetMergeByKeyDelegate(root);
        }
Ejemplo n.º 2
0
        private static void FillProperties(
            MetadataModel model,
            EntityMetadata entity,
            ImmutableList <ScalarProperty> .Builder scalarProperties,
            ImmutableList <NavigationPropertyMetadata> .Builder navigationProperties,
            ImmutableList <NavigationPropertyMetadata> .Builder reverseNavigationProperties,
            ImmutableDictionary <ScalarProperty, NavigationPropertyMetadata> .Builder foreignKeys)
        {
            // Skalar Properties
            foreach (var prop in entity.GetProperties())
            {
                scalarProperties.Add(prop);
            }

            // Navigation Properties
            foreach (var prop in entity.GetNavigations())
            {
                navigationProperties.Add(prop);
            }

            // Reverse-Navigation Properties inkl. aller Base-Entities ermitteln
            var parent = entity;

            while (parent != null)
            {
                foreach (var prop in model.Entities
                         .SelectMany(p => p.GetNavigations())
                         .Where(p => p.TargetEntity == parent)
                         .Distinct())
                {
                    reverseNavigationProperties.Add(prop);
                }

                parent = parent.BaseEntity;
            }

            // Foreign-Keys ermitteln
            var result = from np in navigationProperties
                         from fk in np.ForeignKeyProperties
                         select new { fk.Dependant, Nav = np };

            result.ToList().ForEach(p => foreignKeys.Add(p.Dependant, p.Nav));
        }