SQL 生产者 - PK 和 FK 约束命名

SQL Producer - PK and FK constraint naming

我们在 运行 数据透视文件时遇到模型问题。看来我们在 PK 和 FK 上遇到了命名冲突(如 this)。

我们的用例是这样的,我们创建了新的 table(例如 tableAB),但是由于命名冲突,未创建 PK(例如 PK_tableA)因为另一个 table(比如说 tableAB)已经定义了这个 PK(PK_tableA)。由于 FK 引用 tableAB 上不存在的 PK,枢轴将停止处理。

有什么方法可以重命名 PK 和 FK 约束吗?特别是我们已经使用自定义 class 覆盖 SoftFluent.Samples.CustomNamingConvention.FormatNamingConvention,但这似乎只适用于 DF_ 约束(参见 )。 我想用 PK 和 FK 约束实现同样的事情,什么是最好的解决方案?

编辑 2016 年 8 月 7 日

终于找到了对象转换的方法。下面的代码生成具有预期命名的约束:

 public override string GetShortName(IShortNamedObject obj, IDictionary context)
 {
        Object objCopy = obj;
        if (objCopy is Constraint)
        {
            Constraint constraint = objCopy as Constraint;
            if (constraint != null && constraint.Table != null)
            {
                if (constraint.ConstraintType == ConstraintType.PrimaryKey || constraint.ConstraintType == ConstraintType.ForeignKey)
                {
                    var result = constraint.Table.Name + base.GetShortName(obj, context);
                    return result;
                }
            }

        }
        return base.GetShortName(obj, context);
 }

感谢您提供的支持。

命名约定可以支持多种不同类型的名称(全名、短名、显示名等),具体取决于推理处理的抽象概念的类型(约束、table、过程等)管道,这是 CodeFluent 的 INamingConvention(在 CodeFluent.Model.Common.Naming 命名空间中)的定义方式:

public interface INamingConvention
{
    string GetName(INamedObject obj, IDictionary context);
    string GetShortName(IShortNamedObject obj, IDictionary context);
    string GetFullName(IFullNamedObject obj, IDictionary context);
    string GetDisplayName(IDisplayNamedObject obj, IDictionary context);
    string GetClrFullTypeName(IClrFullTypeNamedObject obj, IDictionary context);
    string GetPersistenceName(IPersistenceNamedObject obj, IDictionary context);
    string GetPersistenceShortName(IPersistenceShortNamedObject obj, IDictionary context);
}

约束使用简称和全名,因此如果您从 FormatNamingConvention(它实现了 INamingConvention)派生,您应该覆盖 GetShortName and/or GetFullName 方法并强制转换 obj 作为 Constraint.

请注意,短名称有这么多问题是不常见的,或者您的所有实体可能在模型版本中一遍又一遍地以相同的名称开头。您还可以使用 persistenceShortNameLength 属性调整短名称长度(默认设置为 3):CodeFluentRuntimeException (CF1024): Cannot determine short name