private static void CloneKeys(IReadOnlyEntityType sourceEntityType, IMutableEntityType targetEntityType) { foreach (var key in sourceEntityType.GetDeclaredKeys()) { var clonedKey = targetEntityType.AddKey( key.Properties.Select(p => targetEntityType.FindProperty(p.Name)).ToList()); if (key.IsPrimaryKey()) { targetEntityType.SetPrimaryKey(clonedKey.Properties); } key.GetAnnotations().ForEach(annotation => clonedKey[annotation.Name] = annotation.Value); } }