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

  • Home
  • SEARCH
  • 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 3608216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:28:26+00:00 2026-05-18T21:28:26+00:00

I am trying to develop a system that has 2 tiers: a mobile client

  • 0

I am trying to develop a system that has 2 tiers: a mobile client and a server that uses LINQ to SQL to store information in the database.
I want to create a WCF server that stores a task in the server, so it will receive a Task from the client and will use LINQ to SQL to store it.

To do this service, I created the dbml file, so I can use the datacontext.

This is my service method:

public Task SaveTask(string token, Task task)
    {
        TrackingDataContext dataConext = new TrackingDataContext();


        //Saves/Updates the task
        dataConext.Tasks.InsertOnSubmit(task);
        dataConext.SubmitChanges();

        return task;
    }

the token will be used in the future

And this is my client method, which will call the service:

private void btnSave_Click(object sender, EventArgs e)
    {
        //Populate the object with the info
        Task task = new Task();
        task.Title = tbTitle.Text;
        task.Description = tbDescription.Text;
        //this is a FK to another table
        task.Severity = ((Severity)lbSeverities.SelectedItem);
        //the first state: "open"
        task.StateID = 1;

        //Save the task
        client.SaveTaskCompleted += new EventHandler<SaveTaskCompletedEventArgs>(client_SaveTaskCompleted);
        client.SaveTaskAsync(App.Token, task);
    }

As you can see, I am creating a new object, populating it and sending it to my service, which will get it and store it. Theoretically it would work ok.

The client is able to create the object and send to the server.
When the server receives the request, it tried to build the object again, but then I get a System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException in this method (created automatically from VS2010):

 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_SeverityID", DbType="Int NOT NULL")]
        public int SeverityID
        {
            get
            {
                return this._SeverityID;
            }
            set
            {
                if ((this._SeverityID != value))
                {
                    if (this._Severity.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnSeverityIDChanging(value);
                                    //The exception happens in this line                    
                                    this.SendPropertyChanging();
                    this._SeverityID = value;
                    this.SendPropertyChanged("SeverityID");
                    this.OnSeverityIDChanged();
                }
            }
        }

It can’t be any error in my server method because:
1- it is very simple and has no logic inside
2- I can’t even debug it, the error happens before my methos is called, probably when unmarshaling the request.

What could happen something like this? Where can I take a look? Could that be a configuration issue?

Thank you,
Oscar

Edit: found this link Serializing Linq2Sql over Wcf – bug or misunderstanding?, where they tell it is a bug, but it is from 1 year ago. Does anyone know if it was solved?

  • 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-05-18T21:28:26+00:00Added an answer on May 18, 2026 at 9:28 pm

    So basically what’s happening here is that the client is sending a materialized object graph. The Task object has a Severity property and a corresponding SeverityID property. When the server deserializes the client’s request, it creates a Task object, then probably deserializes the Severity property first. Now when SeverityID is deserialized, a limitation of LINQ to SQL is being hit…

    if (this._Severity.HasLoadedOrAssignedValue) {
        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
    }
    

    You can’t set a foreign key property (SeverityID) if the related object’s property (Severity) is already set.

    I suspect that this is why LINQ to SQL calls its serialization mode “unidirectional” because passing a materialized collection back will result in this kind of problem.

    Instead of setting the Severity property on the client, try setting the SeverityID property instead. You could also try disabling deferred loading on the server but I don’t know if this will have any effect.

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

Sidebar

Related Questions

I've been trying to develop a linq query that returns the ItemNumber column of
I'm trying to develop an application that will use getImageData in javascript in Firefox
I'm trying to develop a little C# application (with MS Visual Express and SQL
I'm trying to develop a firefox extension that inserts additional HTTP header fields into
I'm trying to develop a simple management system for press releases for my company
I'm trying to develop a site that recommends items(fx. books) to users based on
I'm trying to develop a system, and doing the ER diagram now, i have
We are trying to develop a real-time display system in safety critical domain. (All
I am trying to develop a system where this application allows user to book
I'm trying to develop a program that takes requests for data which is stored

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.