Prevent Nhibernate schemaexport from generating foreign key constraints on has many relationship

社会主义新天地 提交于 2019-12-29 05:18:26

问题


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?


回答1:


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"



来源:https://stackoverflow.com/questions/2826725/prevent-nhibernate-schemaexport-from-generating-foreign-key-constraints-on-has-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!