[英]Fluent NHibernate ignore property inside the ClassMap, using FluentMappings
[英]NHibernate ClassMap get column name for property
我有ClassMap和实体。 在代码中,我想获取实体属性的列名。 任何想法?
public class AccountToDepotMap : ClassMap<AccountToDepot>
{
public AccountToDepotMap()
{
Table("COPS_WPA_ACCOUNT_DEPOT");
Id(t => t.RecId, "REC_ID");
Map(t => t.RecordDate, "REC_DATE");
Map(t => t.DepotId, "WPA_DEPOT_ID");
Map(t => t.AccountId, "WPA_ACCOUNT_ID");
Map(t => t.IsActive, "ISACTIVE").CustomType<YesNoType>();
}
}
public class AccountToDepot
{
public virtual long RecId { get; set; }
public virtual DateTime RecordDate { get; set; }
public virtual string DepotId { get; set; }
public virtual string AccountId { get; set; }
public virtual bool IsActive { get; set; }
}
我想问一下属性DepotId
,结果将是WPA_DEPOT_ID
。
有一个深入的概述:
还有这里的简单代码段
如何从NHibernate中的审核事件侦听器中获取数据库列名
如何获得持久性:
var entityType = typeof(TEntity);
var factory = ... // Get your ISessionFactory
var persister = factory.GetClassMetadata(entityType) as AbstractEntityPersister;
以后可以迭代
// the set of Properties
var propertyNameList = persister.PropertyNames;
// here we get all the settings for remaining mapped properties
foreach (var propertyName in propertyNameList)
{
...
使用上面的代码
这在我的情况下有效
List<string> columns = new List<string>();
for (int i = 0; i < persister.PropertyNames.Count(); i++)
{
if (persister.GetPropertyColumnNames(i).Count() > 0)
{
columns.Add(persister.GetPropertyColumnNames(i).ToList().First());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.