PoonamS
PoonamS

Reputation: 1

How to retrieve table name from database mapping class C# fluent nhibernate

I have itemMap class

 public class ItemMap : ClassMap<Item>
{
     public ItemMap()
    {
        Table("item");
        Id(x => x.Id).GeneratedBy.Identity().Column("id");
        Map(x => x.Inserted).Column("inserted").Not.Nullable()
    }
 }

What are the options of getting table name "item" from the code using C# reflection?

Upvotes: 0

Views: 260

Answers (1)

hightech
hightech

Reputation: 1810

Here is an extensionmethod for getting the tablename for a mapped class:

    public static string GetTableNameFromClass<T>(this ISession session)
    {
        var abstractEntityPersister = session.SessionFactory.GetClassMetadata(typeof(T)) as AbstractEntityPersister;

        return abstractEntityPersister?.TableName.Replace("[", "").Replace("]", "");
    }

Upvotes: 1

Related Questions