c# - How to execute the following SQL-Query using LINQ or HQL -


how can execute following query using castle activerecords , linq or hql?

select a.id, s.classes, count(p.id), max(p.date) last, min(p.date) first
account a
left join school s on s.account_id = a.id
left join user u on u.account_id = a.id
left join points p on p.user_id = u.id
payment = "s"
group a.id

the tables related in following way: er-diagramm

i have activerecord classes tables correct relations defined (if query in steps works, slow there lot of rows) , tried following didn't worked:

var result = account in accountrecord.queryable              join s in schoolrecord.queryable on account equals s.account schools              school in schools.defaultifempty(null)              join user in userrecord.queryable on account equals user.account              join p in pointsrecord.queryable on user equals p.user points              account.paymenttype == "s"              select new { account = account, school = school, count = points.count() }; 

which threw following the method or operation not implemented-exception at:

nhibernate.linq.visitors.querymodelvisitor.visitgroupjoinclause(groupjoinclause groupjoinclause, querymodel querymodel, int32 index)

found solution using hql - i'm still open linq solution:

hqlbasedquery query = new hqlbasedquery(typeof(accountrecord),     "select a, s, count(p), min(p.dateutc), max(p.dateutc) " +     "from accountrecord " +     "left join a.schools s " +     "left join a.users u " +     "left join u.points p " +     "where a.paymenttype=:payment group a.id"); query.setparameter("payment", "s"); var result = object[] row in (arraylist)activerecordmediator.executequery(query)                 select new                 {                     account = row[0] accountrecord,                     school = row[1] schoolrecord,                     count = row[2],                     first = (new datetime(1970, 1, 1, 0, 0, 0, 0)).addseconds(convert.todouble(row[3])),                     last = (new datetime(1970, 1, 1, 0, 0, 0, 0)).addseconds(convert.todouble(row[4]))                 }; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -