I am using latest version of Fluent NHibernate automapping. Is there any convention or property I can set to stop creating the foreign key constraints across all the tables? I have nearly 200 classes, So I cannot go to each individual class and property name and set

 ForeignKeyConstraintNames("none", "none") 

How can we add ForeignKeyConstraintNames("none", "none") in Automapping? I don't want to hardcode the table name or column name. I would like to have the AutoMapping create all the mappings without foreign keys. Basicall don't create any foreign keys across the database. How can we do this? There is similar POST HERE but the answer was not clear to me.

有帮助吗?

解决方案

a simple convention

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))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top