I have the following data model:

I am writing a WCF service that needs to support adding new Report:
public bool CreateNewReport(Report report)
{
MyEntities context = new MyEntities();
context.AddToReports(Report);
context.SaveChanges();
}
So my method gets a report object that was made on the client and adds it to the database throught the data context. (all of the members are included in the DataContract)
My question is regarding navigation properties.
- Do the client also needs to create a user object and put it in the new report object before sending it ?
- What is the best way to approach this ? one way i think of is adding a
UserIdfield in theReportEntity - when a new report is inserted, how do i update the UserEntity Report nav property that with the new Report ?
Thanks.
If you import your database, generate navigation properties (the properties in your picture) AND foreign id properties (then you have for example an User and UserID property in your report class). This way you can set the UserID in your client and send it to the server and add it with
AddToReports… If you send the whole user object you have to attach it to the entity context otherwise the user will be created once again…Attach the referenced user: (but it’s better to send the user only by id)
To change the report of a user:
For an existing report:
This is a sample how your model should look like. Double click on the association line to open the dialog. You can see that the

PersonandPersonIDproperties are the same. If you create your model like this, VS should generate the correct SQL.