Using ASP.NET WebAPI, and EF 5.0. I've created a data provider that will query the database and then return an object or collection of objects to my client, which happens to be an html5/angularjs app.
The problem is with the updating. So for example, if I have a Course, which can have many Students. So I have a Course
table and a Student
table with an fk to StudentId. If I need to edit a student, the EF objects contain everything about a student, including the CourseId, and the Course object itself.
Because of this looping reference, WebAPI pukes when trying to serialize this data, so lazy loading is off- so when I get my Student poco, Course is null.
And then when I update that Student on the client side and then PUT back to my WebAPI, I can't update the DB due to A referential integrity constraint violation occurred
.
I could make DTO's but before I go that route are there other patterns I should look at to overcome this problem? Suggestions on other tools or packages to simplify this?