Criteria API + SQL

14 views
Skip to first unread message

mynkow

unread,
Oct 24, 2011, 11:13:27 AM10/24/11
to nhu...@googlegroups.com
Hi,

I want to add a specific SQL to 1 query which will work only on MSSQL. How to do that:

Criteria:
                 Session
                    .CreateCriteria<User>()
                    .Add(Expression.Sql("TABLESAMPLE (100 PERCENT)"))
                    .SetMaxResults(count)
                    .List<User>();
Generated SQL:
SELECT
TOP (6)
 this_.user_id
FROM users this_
WHERE TABLESAMPLE (100 PERCENT)

EXPECTED SQL:
SELECT
 TOP (6)
  this_.user_id
FROM users this_
TABLESAMPLE (100 PERCENT)

The WHERE keyword should no exist. How to do that without using raw sql for the whole query?

10x

Reply all
Reply to author
Forward
0 new messages