DB table:
- Mcourse(Master course )-> contains Course Names
- Lcourse(Linked
Course- courses belongs to a college) -> contains foreign key
Mcourse_Id. & college Id.
Nw the problem is
I want to display list of courses available in a college using dropdownlist.
So sql query is:
select Lcourse_Id, Mcourse_Name* from Lcourse inner join Mcourse on Lcourse_Mcourse_Id=Mcourse Id..
*Id & value pair for dropdownlist
I could do this usin createCommand..Its working pretty fine. But i cant do this usin Relations ..Help me.
Let’s imagine for a minute that your
Mcoursetable is calledcoursesand model for that table is calledCourses, yourLcoursetable is calledcourses_collegesand your colleges table iscollegesand model for that table isCollegesNow, You should have
Coursesmodel with relations:Your
Collegesmodel should have similar relations:Now if you want to print out a dropdown with all courses available for a certain college. In your controller action method get the model of that college including its courses:
Now in your view print out this:
Where
'id'and'name'are columns of yourCoursesmodel.Something like that.