c# - 3 Table LINQ query with a where clause -
this simple yet evil linq query giving me problems @ runtime (note appropriate clause works long i'm not using joins:
var query = iday in db.datetimeslot join tsk in db.tasks on iday.fktask equals tsk.pktask join dte in db.mdate on iday.fkdate equals dte.pkdate dte.mdate1 == day.tostring(dtform) select new { tsk.pktask, tsk.task, iday.fktask, iday.timeslot, iday.mdate, dte.mdate1 };
i can clause work @ runtime if it's applies db.datetimeslot column. otherwise, query works if remove clause. if try use proper cause, 1 listed here, receive 'unhandled exception: system.argumentexception: value not fall within expected range' error when try foreach through var query result. note when strip out join clauses, clause indeed work, when query proper table.
the schema of database is:
tasks -∞ datetimeslot ∞- mdate
i trying list of tasks related mdate.date, clause tests mdate.date.
thanks
edit: here sqlite db schema portion:
create table mdate ( pkdate integer primary key autoincrement, mdate text, nday text); create table datetimeslot ( pkdts integer primary key autoincrement, timeslot integer, fkdate integer, fktask integer, foreign key(fkdate) references mdate(pkdate) foreign key(fktask) references tasks(pktask)); create table mdate ( pkdate integer primary key autoincrement, mdate text, nday text);
edit: here sql statement works:
sqlite> select tasks.task, mdate.mdate datetimeslot ...> inner join tasks on datetimeslot.fktask=tasks.pktask ...> inner join mdate on datetimeslot.fkdate=mdate.pkdate ...> mdate.mdate = '2011-07-21'; task|mdate laundry|2011-07-21 laundry|2011-07-21
edit: here output of db.log = console.out. note don't sql spam if clause left in, getting normal exception debug spam:
select tsk$.[pktask], tsk$.[task], iday$.[fktask], iday$.[timeslot], t1$.[mdate], t1$.[nday], t1$.[pkdate], dte$.[mdate] [main].[datetimeslot] iday$ left join [main].[mdate] t1$ on t1$.[pkdate] = iday$.[fkdate] inner join [main].[mdate] dte$ on iday$.[fkdate] = dte$.[pkdate] inner join [main].[tasks] tsk$ on iday$.[fktask] = tsk$.[pktask] -- context: sqlserver model: attributedmetamodel build: 4.0.0.0
i posted full error at: here
solved! replaced day.tostring(dtform) with: tdate tdate local string = day.tostring(dtform)
your exception output highlights problem l2s provider using cannot convert day.tostring(dtform)
comprehensible form sqlite.
the nice thing fixed string query, , not depend on anything. you'll have remove query, lift local variable:
var mdate1 = day.tostring(dtform); var query = iday in db.datetimeslot join tsk in db.tasks on iday.fktask equals tsk.pktask join dte in db.mdate on iday.fkdate equals dte.pkdate dte.mdate1 == mdate1 select new { tsk.pktask, tsk.task, iday.fktask, iday.timeslot, iday.mdate, dte.mdate1 };
the relevant part of exception analyzetostring
bit points in direction:
unhandled exception: system.argumentexception: value not fall within expected range. @ dblinq.data.linq.sugar.implementation.expressiondispatcher.analyzetostring (system.reflection.methodinfo method, ilist`1 parameters, dblinq.data.linq.sugar.buildercontext buildercontext) [0x00151] in /var/tmp/portage/dev-lang/mono-2.10.2-r1/work/mono-2.10.2/mcs/class/system.data.linq/src/dblinq/data/linq/sugar/implementation/expressiondispatcher.analyzer.cs:466 @ dblinq.data.linq.sugar.implementation.expressiondispatcher.analyzeunknowncall (system.linq.expressions.methodcallexpression expression, ilist`1 parameters, dblinq.data.linq.sugar.buildercontext buildercontext) [0x0008d] in /var/tmp/portage/dev-lang/mono-2.10.2-r1/work/mono-2.10.2/mcs/class/system.data.linq/src/dblinq/data/linq/sugar/implementation/expressiondispatcher.analyzer.cs:345 @ dblinq.data.linq.sugar.implementation.expressiondispatcher.analyzecall (system.linq.expressions.methodcallexpression expression, ilist`1 parameters, dblinq.data.linq.sugar.buildercontext buildercontext) [0x00040] in /var/tmp/portage/dev-lang/mono-2.10.2-r1/work/mono-2.10.2/mcs/class/system.data.linq/src/dblinq/data/linq/sugar/implementation/expressiondispatcher.analyzer.cs:178
Comments
Post a Comment