NHibernate:查找属性是否映射到字段
是否有办法确定属性是否映射到字段。 我希望这可以生成类似“通用搜索”的内容: 如果我添加一个未映射到NHibernate的属性,搜索将抛出一个NHibernate.QueryException,其描述为“无法解析属性:Text1 of:C” 我正在映射如下属性:NHibernate:查找属性是否映射到字段,nhibernate,properties,nhibernate-mapping,nhibernate-metadata,Nhibernate,Properties,Nhibernate Mapping,Nhibernate Metadata,是否有办法确定属性是否映射到字段。 我希望这可以生成类似“通用搜索”的内容: 如果我添加一个未映射到NHibernate的属性,搜索将抛出一个NHibernate.QueryException,其描述为“无法解析属性:Text1 of:C” 我正在映射如下属性: class C { [Property(0, Column = "comment")] public virtual string Comment {get; set;} } 使用NHibernate元数据AP
class C
{
[Property(0, Column = "comment")]
public virtual string Comment {get; set;}
}
使用NHibernate元数据API
ISessionFactory sessionFactory;
Type type = typeof(T);
IClassMetadata meta = sessionFactory.GetClassMetadata(type);
Disjunction disjunction = new Disjunction();
foreach (string mappedPropertyName in meta.PropertyNames)
{
IType propertyType = meta.GetPropertyType(mappedPropertyName);
if (propertyType == NHibernateUtil.String)
{
foreach (string word in words)
{
disjunction.Add(
Expression.InsensitiveLike(
mappedPropertyName,
"%" + word + "%"));
}
}
}
ISessionFactory sessionFactory;
Type type = typeof(T);
IClassMetadata meta = sessionFactory.GetClassMetadata(type);
Disjunction disjunction = new Disjunction();
foreach (string mappedPropertyName in meta.PropertyNames)
{
IType propertyType = meta.GetPropertyType(mappedPropertyName);
if (propertyType == NHibernateUtil.String)
{
foreach (string word in words)
{
disjunction.Add(
Expression.InsensitiveLike(
mappedPropertyName,
"%" + word + "%"));
}
}
}