开发者

translate a mysql query into nhibernate

开发者 https://www.devze.com 2023-01-02 16:26 出处:网络
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,dayofy

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

精彩评论

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