开发者

Prefix string to ALL generated table names - FluentNHibernate

开发者 https://www.devze.com 2023-03-14 04:40 出处:网络
Is there a simple way to prefix all generated table names with a string? The convention Table.Is(x => \"Prefix\" + x.EntityType.Name)

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!


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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号