Nhibernate拦截器 – 获取属性长度OnSave

我有简单的NHibernate拦截器和覆盖方法OnSave()。

现在我要做的是获取字符串属性的SQL长度。 那可能吗。

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

在此处输入图像描述

这是我所拥有的代码的示例,以及我在哪里尝试获取Sql属性的长度。

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

任何帮助我怎么能得到这个?

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

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