How do I select 5 random records using nhibernate.
My sql looks like this:
SELECT TOP 5 u.UserId, u.UserName, p.ImageFileName FROM users as u, profiles as p WHERE u.UserId = p.UserId ORDER BY NEWID()
I tried doing this but it doesn't work
IList<User> users = session
.CreateCriteria(typeof(User))
.CreateCriteria("Profile")
.Add<Profile>(p => p.ImageFileName != string.Empty)
.AddOrder(Order.Asc("NEWID()"))
.SetMaxResults(5)
.List<User>();