queryover - NHibernate: how to select a sorted parent/child and retrieve only specific row_numbers -
i have 2 tables: parent , child have following relation: parent has many childs.
public class parent { public datetime timestamp; public ilist<child> child; } public child { public string name; }
i want select both parent , child, sorted timestamp , rows between index x y.
public ilist<parent> get(datetime from, datetime to, int startrow, int count) { queryover<parent>().where(row => row.timestamp >= from) .and(row => row.timestamp <= to).orderby(row => row.timestamp).asc.list(); }
i don't know how required rows.
should queryover? or better doing in hql?
thanks
i changed relation , instead of having parent , child use 1 table:
public class info { public datetime timestamp; public string name; }
in order records between dates, sorted , them index startrow startrow + count used following:
public ilist<info> getinfo (datetime fromdate, datetime todate, int startrow, int count) { ilist<info> result = queryover<info>() .where(row => row.timestamp >= fromdate) .and(row => row.timestamp <= todate) .orderby(row => row.timestamp).asc .skip(startrow).take(count).list(); return result; }
the resulted sql is:
select * info timestamp >= :fromdate , timestamp <= :todate order timestamp asc offset :startrow rows fetch next :count rows
Comments
Post a Comment