Exemple #1
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public ColumnBase([NotNull] string name, [NotNull] string type, [NotNull] TableBase table)
 {
     Name      = name;
     StoreType = type;
     Table     = table;
 }
Exemple #2
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public ColumnBase(string name, string type, TableBase table)
 {
     Name      = name;
     StoreType = type;
     Table     = table;
 }
        private static void PopulateInternalForeignKeys(TableBase table)
        {
            SortedDictionary <IEntityType, IEnumerable <IForeignKey> > internalForeignKeyMap            = null;
            SortedDictionary <IEntityType, IEnumerable <IForeignKey> > referencingInternalForeignKeyMap = null;

            foreach (var entityTypeMapping in ((ITableBase)table).EntityTypeMappings)
            {
                var entityType = entityTypeMapping.EntityType;
                var primaryKey = entityType.FindPrimaryKey();
                if (primaryKey == null)
                {
                    continue;
                }

                SortedSet <IForeignKey> internalForeignKeys = null;
                foreach (var foreignKey in entityType.FindForeignKeys(primaryKey.Properties))
                {
                    if (foreignKey.IsUnique &&
                        foreignKey.PrincipalKey.IsPrimaryKey() &&
                        !foreignKey.IsIntraHierarchical() &&
                        ((ITableBase)table).EntityTypeMappings.Any(m => m.EntityType == foreignKey.PrincipalEntityType))
                    {
                        if (internalForeignKeys == null)
                        {
                            internalForeignKeys = new SortedSet <IForeignKey>(ForeignKeyComparer.Instance);
                        }
                        internalForeignKeys.Add(foreignKey);

                        if (referencingInternalForeignKeyMap == null)
                        {
                            referencingInternalForeignKeyMap =
                                new SortedDictionary <IEntityType, IEnumerable <IForeignKey> >(EntityTypePathComparer.Instance);
                        }

                        var principalEntityType = foreignKey.PrincipalEntityType;
                        if (!referencingInternalForeignKeyMap.TryGetValue(principalEntityType, out var internalReferencingForeignKeys))
                        {
                            internalReferencingForeignKeys = new SortedSet <IForeignKey>(ForeignKeyComparer.Instance);
                            referencingInternalForeignKeyMap[principalEntityType] = internalReferencingForeignKeys;
                        }
                        ((SortedSet <IForeignKey>)internalReferencingForeignKeys).Add(foreignKey);
                    }
                }

                if (internalForeignKeys != null)
                {
                    if (internalForeignKeyMap == null)
                    {
                        internalForeignKeyMap =
                            new SortedDictionary <IEntityType, IEnumerable <IForeignKey> >(EntityTypePathComparer.Instance);
                        table.InternalForeignKeys = internalForeignKeyMap;
                    }

                    internalForeignKeyMap[entityType] = internalForeignKeys;
                }

                if (internalForeignKeys == null &&
                    ((ITableBase)table).EntityTypeMappings.Any(m => !m.EntityType.IsSameHierarchy(entityType)))
                {
                    table.IsSplit = true;
                }
            }

            if (referencingInternalForeignKeyMap != null)
            {
                table.ReferencingInternalForeignKeys = referencingInternalForeignKeyMap;
            }
        }