Nhibernate拦截器-获取属性长度OnSave [英] Nhibernate Interceptor - Get Property length OnSave

查看:110
本文介绍了Nhibernate拦截器-获取属性长度OnSave的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的NHibernate拦截器和重写方法OnSave().

I have simple NHibernate interceptor and override method OnSave().

现在我要在这里执行的操作是获取字符串属性的SQL长度. 那可能吗.

Now what I am trying to do here is to get SQL length for string properties. Is that possible.

我可以看到属性IType[]类型包含SqlType,其中Length可用,但是找不到如何读取它.调试示例:

I can see that property IType[] types contains SqlType where Length is available, but just cannot find how to read it. Example from debug:

这是我所拥有的代码示例,也是我试图获取Sql属性长度的地方.

This is example of the code which I have, and where I am trying to get Sql length of property.

public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
    for (int i = 0; i < propertyNames.Length; i++)
    {
        //If type is string
        if (types[i].GetType() == typeof(NHibernate.Type.StringType))
        {
             //Get SQL length of string property   
        }
    }

    return false;
}

有什么帮助我能得到这个吗?

Any help how I can get this?

推荐答案

让我们尝试将IType转换为预期的版本:

Let's just try to cast the IType into intended one:

//If type is string
var stringType = types[i] as NHibernate.Type.StringType;

//if (types[i].GetType() == typeof(NHibernate.Type.StringType))
if(stringType != null)
{
     //Get SQL length of string property   
     var length = stringType.SqlType.Length;
}

这篇关于Nhibernate拦截器-获取属性长度OnSave的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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