[英]Nhibernate Interceptor - Get Property length OnSave
I have simple NHibernate interceptor and override method OnSave(). 我有简单的NHibernate拦截器和覆盖方法OnSave()。
Now what I am trying to do here is to get SQL length for string properties. 现在我要做的是获取字符串属性的SQL长度。 Is that possible. 那可能吗。
I can see that property IType[]
types contains SqlType
where Length
is available, but just cannot find how to read it. 我可以看到属性IType[]
类型包含SqlType
,其中Length
可用,但是找不到如何读取它。 Example from debug: 调试示例:
This is example of the code which I have, and where I am trying to get Sql length of property. 这是我拥有的代码的示例,以及我在哪里尝试获取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;
}
Any help how I can get this? 任何帮助我怎么能得到这个?
Let's just try to cast the IType
into intended one: 让我们尝试将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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.