【问题标题】:Prevent Nhibernate schemaexport from generating foreign key constraints on has many relationship防止 Nhibernate schemaexport 在有很多关系上生成外键约束
【发布时间】:2010-05-13 12:31:37
【问题描述】:

我有这样的映射:

HasMany(x => x.Orders).KeyColumn("CustomerID");

这会导致 schemaexport 生成这样的约束:

alter table [CustomerOrder] 
    add constraint FK45B3FB85AF01218D 
    foreign key (CustomerID) 
    references [Customer]

我尝试在 References() 映射上添加 .NotFound.Ignore() 以禁用生成约束,但这不起作用。

是否可以定义强制 SchemaExport 不生成约束的映射?

【问题讨论】:

    标签: nhibernate fluent-nhibernate nhibernate-mapping schemaexport


    【解决方案1】:

    想通了:

    HasMany(x => x.Orders).KeyColumn("CustomerID").ForeignKeyConstraintName("none");
    

    如果名称为“none”,则隐藏在源中是一个忽略创建的检查

    【讨论】:

    • 感谢您的发现!我需要这个来防止跨数据库外键>.
    • 在更高版本的 FluentNHibernate 中,您使用.ForeignKey("none") 来完成此操作; .ForeignKeyConstraintName() 不再是一个函数。
    • 有没有类似的技术来防止.UniqueKey("xyz").Unique()被生成?
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    相关资源
    最近更新 更多