NHibernate ClassMap获取属性的列名 [英] NHibernate ClassMap get column name for property

查看:116
本文介绍了NHibernate ClassMap获取属性的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ClassMap和实体.在代码中,我想获取实体中属性的列名.有想法吗?

I have ClassMap and entity. In code I would like to get column names for properties in entity. Any Idea?

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.

I would like to ask on property DepotId and result will be WPA_DEPOT_ID.

推荐答案

有很深的概述:

探索nhibernate映射

还有这里的简单代码段

如何从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)
{
    ...

这篇关于NHibernate ClassMap获取属性的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆