Reputation: 2284
I am using NHibernate in my project, but I dont like to use typed properties for selecting items from database. Is it possible to have instead of
session.CreateCriteria(typeof(IEntry)).AddOrder(Order.Desc("Alias"))
somthing like this
session.CreateCriteria(typeof(IEntry)).AddOrder(Order.Desc(x=>x.Alias))
Thanks, Alexander.
I tried to use NHibernate.Link, but I can't use because it has no strong name :( Will wait for next version and continue to use my solution now
Upvotes: 3
Views: 1449
Reputation: 25946
With NH 2 you could use the nh lambda extensions
list = session.CreateCriteria(typeof(Cat))
.Add<Cat>( c => c.Age >= 2 && c.Age <= 8 )
.AddOrder<Cat>( c => c.Name, Order.Desc )
.List<Cat>();
In NH 3, you would use QueryOver
list = session.QueryOver<Cat>()
.WhereRestrictionOn(c => c.Age).IsBetween(2).And(8)
.OrderBy(c => c.Name).Desc
.List<Cat>();
Or you could use NHibernate.Linq
list = (from c in session.Linq<Cat>()
where c.Age >= 2 && c.Age <= 8
orderby c.Name descending
select c).ToList<Cat>();
Upvotes: 9