【问题标题】:How can I stop Fluent NHibernate automapping from creating foreign keys across the database?如何阻止 Fluent NHibernate 自动映射跨数据库创建外键?
【发布时间】:2013-05-21 02:41:43
【问题描述】:

我正在使用最新版本的 Fluent NHibernate 自动映射。我可以设置任何约定或属性来停止在所有表中创建外键约束吗?我有近 200 个类,所以我不能去每个单独的类和属性名称并设置

 ForeignKeyConstraintNames("none", "none") 

我们如何在 Automapping 中添加 ForeignKeyConstraintNames("none", "none")?我不想硬编码表名或列名。我想让 AutoMapping 创建所有没有外键的映射。基本不会在数据库中创建任何外键。我们应该怎么做? 有类似的POST HERE,但我并不清楚答案。

【问题讨论】:

    标签: nhibernate fluent-nhibernate foreign-keys fluent-nhibernate-mapping automapping


    【解决方案1】:

    一个简单的约定

    public class NoForeignKeys : IReferenceConvention, IHasManyConvention
    {
        public void Apply(IManyToOneInstance instance)
        {
            instance.ForeignKey("none");
        }
    
        public void Apply(IOneToManyCollectionInstance instance)
        {
            instance.Key.ForeignKey("none");
        }
    }
    
    // use it
    AutoMap.AssemblyOf().Conventions
        .FromAssembly() or .Add(typeof(NoForeignKeys))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多