简体   繁体   中英

Nhibernate Interceptor - Get Property length OnSave

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

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

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

在此输入图像描述

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?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM