Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please find below the linq query

C#
var result = (from sd in students
                              select sd.Student_ID).Except(from m in query1
                                                          select m.Student_ID).ToList();


from this query I am getting the exact results. Now I want to populate other data of students so what I have done is wrote other linq query. Below here, But I am not getting r.Student_ID attribute to compare with students table. Intellisense not giving r.Student_ID. Please help!

C#
var finalResult = (from sd in dbcDefaulter.Student_Details
                               from r in list where r == sd.Student_ID
                               orderby sd.Student_ID
                               select new { sd.Student_ID, sd.Name, sd.Class, sd.Section, sd.F_Name, sd.F_Mobile }).Distinct().ToList();
Posted
Updated 20-Sep-14 0:26am
v2
Comments
SandeepKushwah 20-Sep-14 13:00pm    
Any One there to help on it?
Jameel VM 21-Sep-14 3:06am    
why you are not try to join the two collection?

1 solution

1.You should declare your first LINQ expression, but not to execute it, like below:
C#
var firstQuery= from sd in students
                                from m in query1
                                where sd.Student_ID != m.Student_ID 
                              select sd.Student_ID;

2.Then use the above first query in the second one like below:
C#
var finalResult = (from sd in dbcDefaulter.Student_Details
                                  from r in firstQuery where r.Student_ID == sd.Student_ID
                                  orderby sd.Student_ID
                                  select new { sd.Student_ID, sd.Name, sd.Class, sd.Section, sd.F_Name, sd.F_Mobile }).Distinct().ToList();
 
Share this answer
 
Comments
SandeepKushwah 21-Sep-14 15:01pm    
`firstquery` not giving me the intended result.
Raul Iloc 22-Sep-14 1:10am    
1.I created first query based on your old one, and should return the same results. If something is missing you could change its filter as you want. Not that this first query is executed only in the second one so you cannot see results of it in the debug
2.Did you test like I suggested?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900