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) ?
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
select t.ID
where ckey.Contains(db.ID) == true
select db).ToList();
}
Hi thaicarrot and thank you for your responce a lot!
It's linking table between two tables
Tables columns summary(simple):
Teacher: id
Teacher_Subject: teacher_id, subject_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
s.id
and
(from ts in ldc.Teacher_Subjects where ts.teacher_id == currentTeacherID select ts.subject_id)
which returns sequence of System.Linq.IQueryable<int>.
Mastenka
None
0 Points
3 Posts
Multiple rows return with IQueryable Query
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
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
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Multiple rows return with IQueryable Query
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 select t.ID where ckey.Contains(db.ID) == true select db).ToList(); }return nonEquijoinQuery;
Weera
Mastenka
None
0 Points
3 Posts
Re: Multiple rows return with IQueryable Query
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: id
Teacher_Subject: teacher_id, subject_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
and
which returns sequence of System.Linq.IQueryable<int>.
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Multiple rows return with IQueryable Query
Jan 26, 2013 08:15 PM|LINK
var results = from ts in ldc.Teacher_Subjects where ts.teacher_id == currentTeacherID select ts.subject_id;
Weera
Mastenka
None
0 Points
3 Posts
Re: Multiple rows return with IQueryable Query
Jan 26, 2013 08:21 PM|LINK
Thx mate, really appreciate your interest in my case!
Wish you all the best
Mastenka