14

I have a mapping like this:

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

Which is causing a constraint like this to be generated by schemaexport:

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

I have tried adding .NotFound.Ignore() like on a References() mapping to disable the constraint from being generated but this does not work.

Can a mapping be defined that will force SchemaExport to not generate the constraint?

Mike Glenn
  • 3,359
  • 1
  • 26
  • 33

1 Answers1

23

Figured it out:

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

buried in the source is a check to ignore creation if the name is "none"

Mike Glenn
  • 3,359
  • 1
  • 26
  • 33
  • 2
    Thanks for the discovery! I needed this to prevent cross-database foreign keys >.< For non-fluent users: foreign-key="none" – Groxx Mar 11 '11 at 20:06
  • 3
    In later versions of FluentNHibernate, you use `.ForeignKey("none")` to accomplish this; `.ForeignKeyConstraintName()` is not a function anymore. – Andrew Gray Aug 18 '16 at 18:41
  • Is there a similar technique to prevent `.UniqueKey("xyz")` and `.Unique()` from being generated? – Stokedout Oct 24 '19 at 15:13