I have a little SQL Server 2012 "School" DB used for testing. It has these TableName(FieldName1, FieldName2....):
Course(CourseNo, CourseName), Student(StudentId, StudentName, Birth), Enrollment(EnrollNo, StudentNo, CourseId)
The Enrollment table uses foreign keys to link a Student to Courses - CourseNo:CourseID and StudentId:StudentNo
When an EF Model-diagram is created in a VS2013 web site, the Enrollment entity shows "navigation" to Course and Student
I've use JSON in an html page to access a "Controller" that uses EF6 and linq to retrieve data from the DB to populate a page in a jQuery Mobile app. The first test is to just list the contents of the "Course" table in an html table. If my EF Model just contains the Course table, the code works perfectly. If I add the Student and Enrollment tables (and do nothing else) the code fails with debugger info saying that JSON couldn't resolve naming issues. All the field names are unique but the Enrollment table navigation shows Course and Student. Apparently, any reference involving the same names causes JSON to fail. As a side test, adding an ASP page to the site with a Gridview, that uses the exact same DB retrieval code, with all three tables present, works perfectly.
Is there something I'm missing when trying to combine JSON and EF6-linq?
Here is the important parts of the html side:
$.getJSON("api/CourseTitles",
function (data) {
$('#coursenames').empty(); // Clear the table body.
// Loop through the list of courses.
$.each(data, function (key, val) {
// Add a table row for the course.
$('#coursenames').append('<tr><td>' + val.CourseNo + ' ' +
'</td><td>' + val.CourseName + '</td></tr>');
});
});
.................
<table>
<thead>
<tr><th>Number</th><th>Name</th></tr>
</thead>
<tbody id="coursenames"></tbody>
</table>
Here is the Controller code:
Public Function GetCourseTitles() As IEnumerable(Of Course)
Dim myContext As New SchoolEntities1()
Return From courselist In myContext.Courses Select courselist
End Function
Edit - This works:
Public Function GetCourseTitles() As IEnumerable(Of Course)
Dim myContext As New SchoolEntities()
myContext.Configuration.ProxyCreationEnabled = False
Return From courselist In myContext.Courses Select courselist
End Function