Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 26, 2013 08:21 PM by Mastenka
Jan 26, 2013 05:44 PM|LINK
Hi (first time here :) ),
I'm having some troubles using IQueryable Query. I need to select multiple rows from one table
IQueryable<Subject> subjectQuery = ldc.Subjects;
subjectQuery = subjectQuery.Where(s => s.id == (
from ts in ldc.Teacher_Subjects where ts.teacher_id ==
currentTeacherID select ts.subject_id).FirstOrDefault());
where I need to select multiple rows from table Subject where Subject ID (s.id) match multiple IDs from table Teacher_Subject (ts.teacher_id which is match for local variable currentTeacherID). However I couldnt find way to select all results. I know that
this is probably reason of FirstOrDefault method, but when I dont use it I get:
Error 2 Operator '==' cannot be applied to operands of type 'int' and 'System.Linq.IQueryable<int>'
So can anyone help me how to get rows from Subject based on multiple IDs from Teacher_Subejct table(which is used to make M:N realationship between Teacher and Subject) (where PK will match specific int) ?
Thank you, extremely much :D
Jan 26, 2013 06:52 PM|LINK
I don't understand much about the Multiple IDs from Techer_Subject table. Is it join table or linking table? Do you know that?
You'd better create an addition method.
internal static IEnumerable<T> FetchingData()
var nonEquijoinQuery =
(from db in this.UContext.Subjects
let ckey = from t in this.Context.Teacher_Subject
where t.ID == db.ID
where ckey.Contains(db.ID) == true
Jan 26, 2013 07:17 PM|LINK
Hi thaicarrot and thank you for your responce a lot!
It's linking table between two tables
Tables columns summary(simple):
Teacher_Subject: teacher_id, subject_id
I have specific teacher (his ID == currentTeacherID) and I need to find all his subjects. But I need to do it with IQueryable (I have searching methods which i will send query and the proceed results), because I have to make many queries which are different
only in where part.
It seems to be a problem in part where I compare
(from ts in ldc.Teacher_Subjects where ts.teacher_id == currentTeacherID select ts.subject_id)
which returns sequence of System.Linq.IQueryable<int>.
Jan 26, 2013 08:15 PM|LINK
var results = from ts in ldc.Teacher_Subjects
== currentTeacherID select ts.subject_id;
Jan 26, 2013 08:21 PM|LINK
Thx mate, really appreciate your interest in my case!
Wish you all the best