コード例 #1
0
 private static void CloneForeignKeys(IReadOnlyEntityType sourceEntityType, IMutableEntityType targetEntityType)
 {
     foreach (var foreignKey in sourceEntityType.GetDeclaredForeignKeys())
     {
         var targetPrincipalEntityType = targetEntityType.Model.FindEntityType(foreignKey.PrincipalEntityType.Name);
         var clonedForeignKey          = targetEntityType.AddForeignKey(
             foreignKey.Properties.Select(p => targetEntityType.FindProperty(p.Name)).ToList(),
             targetPrincipalEntityType.FindKey(
                 foreignKey.PrincipalKey.Properties.Select(p => targetPrincipalEntityType.FindProperty(p.Name)).ToList()),
             targetPrincipalEntityType);
         clonedForeignKey.IsUnique   = foreignKey.IsUnique;
         clonedForeignKey.IsRequired = foreignKey.IsRequired;
         foreignKey.GetAnnotations().ForEach(annotation => clonedForeignKey[annotation.Name] = annotation.Value);
     }
 }
コード例 #2
0
 public static IReadOnlyForeignKey?FindDeclaredOwnership([NotNull] this IReadOnlyEntityType entityType)
 => entityType.GetDeclaredForeignKeys().FirstOrDefault(fk => fk.IsOwnership);