Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:14+00:00 2026-06-01T12:24:14+00:00

I have the following data model: I am writing a WCF service that needs

  • 0

I have the following data model:

enter image description here

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.

  1. Do the client also needs to create a user object and put it in the new report object before sending it ?
  2. What is the best way to approach this ? one way i think of is adding a UserId field in the ReportEntity
  3. when a new report is inserted, how do i update the UserEntity Report nav property that with the new Report ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:24:15+00:00Added an answer on June 1, 2026 at 12:24 pm

    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)

    public bool CreateNewReport(Report report)
    {
        using (MyEntities context = new MyEntities())
        {
             context.AddToReports(Report);
             context.Users.Attach(report.User);
             context.SaveChanges();
        }
    }
    

    To change the report of a user:

    public bool ChangeUserToNewReport(int userid, Report newReport)
    {
        using (MyEntities context = new MyEntities())
        {
             var user = context.Users.Single(u => u.ID = userid);
             user.Report = newReport;
             context.SaveChanges();
        }
    }
    

    For an existing report:

    public bool ChangeUserReport(int userid, Report existingReport)
    {
        using (MyEntities context = new MyEntities())
        {
             context.Reports.Attach(existingReport);
             var user = context.Users.Single(u => u.ID = userid);
             user.Report = existingReport;
             context.SaveChanges();
        }
    }
    

    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 Person and PersonID properties are the same. If you create your model like this, VS should generate the correct SQL.
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data model class defined: @PersistenceCapable public class TestSerializableModelObj { @Persistent(serialized=true,
I have the following data set that I am trying to plot with ggplot2,
I have a partial view that sometimes needs to collect data and sometimes just
I have the following data model: Camp -> CampEvent <- Event. Camp has CampId
I'm writing a few WCF services that expose data being retrieved from the Entity
I have the following data in my database: |NO | model | date |
My Techie Bretheren (and Sisteren, of course!), I have a LinqToSql data model that
If I have the following: {hdrs: [Make,Model,Year], data : [ {Make:Honda,Model:Accord,Year:2008} {Make:Toyota,Model:Corolla,Year:2008} {Make:Honda,Model:Pilot,Year:2008}] }
Let's say I have the following data model, for keeping track of the stats
I have a C# WCF service using a webHttpBinding endpoint that will receive and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.