MonoRail - How to grab records where a column isn't null
In MonoRail/Active Record if I want to grab all records that have a certain column equal to null, I 开发者_运维技巧can do:
public static Category[] AllParentCategories()
{
return (FindAllByProperty("Parent.Id", null));
}
However, what if I want to grab all records where that column doesn't equal null? I can't figure out how to do that using this FindAllByProperty method, is there another method that is more flexible or a way to grab records using a linq-like querying language?
Thanks, Justin
In NHibernate 2.1 (and by extension, Castle ActiveRecord) you basically have three query APIs you can choose from:
- HQL
- Criteria
- Linq
With Criteria:
return ActiveRecordMediator<Category>.FindAll(Restrictions.IsNotNull("Parent"));
With Linq:
return (from c in ActiveRecordLinq.AsQueryable<Category>()
where c.Parent != null
select c).ToArray();
To get Linq support you'll need NHibernate.Linq.dll and Castle.ActiveRecord.Linq.dll (the latest ActiveRecord release includes everything).
精彩评论