MushinNoShin
MushinNoShin

Reputation: 4886

Prefix string to ALL generated table names - FluentNHibernate

Is there a simple way to prefix all generated table names with a string?

The convention

Table.Is(x => "Prefix" + x.EntityType.Name)

only works for Entity tables (doesn't function for join or subclass tables)

I can't seem to find a simple way to have every single table that nhibernate creates be prefixed with a specific string without first identifying all the cases that would create a table and specifying a rule per case. Ew!

Upvotes: 3

Views: 811

Answers (1)

Firo
Firo

Reputation: 30803

for this you have to implement IHasManyToManyConvention and IJoinedSubclassConvention see

public class SubclassConvention : IJoinedSubclassConvention, IHasManyToManyConvention
{
    public void Apply(IJoinedSubclassInstance instance)
    {
        instance.Table("Prefix" + instance.Type.Name);
    }

    public void Apply(IManyToManyCollectionInstance instance)
    {
        instance.Table("Prefix" + instance.TableName);
    }
}

Upvotes: 1

Related Questions