Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SELECT TOP 3 * FROM tbl_LectureScheduling

ORDER BY StartDateTime DESC


I am writing SQL code in .cs file in .NET. So I am usually writing code in following format :
C#
var query =  from LectureAttendance in context.tbl_LectureAttendence
                              join LectureSchedulling in context.tbl_LectureScheduling on LectureAttendance.LectureScheduleID equals LectureSchedulling.LectureScheduleID
                              join Lectures in context.tbl_Lectures on LectureSchedulling.LectureID equals Lectures.LectureID
                              where LectureAttendance.StudentID ==  StudentID
                              select new
                                 {
                                     LectureAttendance.StudentID,
                                     LectureAttendance.LectureScheduleID,
                                     LectureAttendance.status,
                                     LectureSchedulling.LectureID,
                                     LectureSchedulling.StartDateTime,
                                     Lectures.LectureName,

                                   
                                 };

So I dont know how to write above sql query in this format as this is .cs file which does not support keywords like "TOP" and "Order By".
Posted
Updated 10-Aug-14 23:24pm
v2
Comments
george4986 11-Aug-14 5:16am    
search google for topic named 'LINQ'
george4986 11-Aug-14 5:22am    
try this link
http://stackoverflow.com/questions/4872946/linq-query-to-select-top-5
m-shraddha 11-Aug-14 5:57am    
thanku

1 solution

For Ordering the record refer this link

SQL Ordering Operation in LINQ [^]


AND For Top 3,5 .....

write end of the query if you want to get top 3 write Take(3), If you want to take 5 record write Take(5)


Refer

Take examples[^]
 
Share this answer
 

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