[英]How to retrieve table name from database mapping class C# fluent nhibernate
I have itemMap class我有 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?使用 C# 反射从代码中获取表名“item”的选项有哪些?
Here is an extensionmethod for getting the tablename for a mapped class:这是获取映射 class 的表名的扩展方法:
public static string GetTableNameFromClass<T>(this ISession session)
{
var abstractEntityPersister = session.SessionFactory.GetClassMetadata(typeof(T)) as AbstractEntityPersister;
return abstractEntityPersister?.TableName.Replace("[", "").Replace("]", "");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.