开发者

translate a mysql query into nhibernate

Please, can yo开发者_运维百科u help me to translate such a mysql query into nhibernate:

SELECT sales_id, service_id,dayofyear(dt), max(dt) FROM clients.statistics group by sales_id, service_id,dayofyear(dt);


sales_id is a property of Sales class, service_id is a property of Service class


If you have a working SQL query, you can use that with the Hibernate directly. Hibernate can execute those queries, and wrap the query result as objects.

See this doc about mapping a entity class on SQL query. That is from normal Hibernate (not NHibernate) but something similar should work in your case.

First make a class that holds the result from query (eg Result) and contains references to required entities (Sales and Service)

String sql = "SELECT sales_id, service_id,dayofyear(dt), max(dt) "
    "FROM clients.statistics " +
    "group by sales_id, service_id, dayofyear(dt)";
sess.createSQLQuery(sql).addEntity("result", Result.class)
    .addJoin("result.sales").addJoin("result.services");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜