I have a table, say STUDENTS, that is related one-to-many to another table, CLASSES. I created an ASP.Net form to take input of a new student, including selection of one of the classes from a combo box. This is a small but multi-tier app, and I have started using the entity framework. So the EF generated classes for both those tables. On Submit, I am building a STUDENT object and handing it off to my Data controller for inserts, updates, etc.
In the STUDENTS table I have a CLASSID that's a FK to the CLASSES table. Back in the day, when I would do the insert to STUDENTS I would take the SelectedValue from the combo box and stick that into the ClassId field. However, with the EF, the STUDENT object doesn't have this ID field. Instead it has a CLASS field, which is a full-on instance of that class. When the new STUDENT object is built, that CLASS field is null. I want to populate it with the class the user chose in the combo.
I can't leave it null, and I can't just put the ID in there. I tried doing a retrieve of that class record and using that, but I get an error that I can't use the same object with two different contexts. What am I really supposed to be doing here?