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 8014813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:03:40+00:00 2026-06-04T20:03:40+00:00

I have the following situation, I have a WCF Data Service with User objects

  • 0

I have the following situation, I have a WCF Data Service with User objects and message objects and the message object has two relations to user, a sender and a receiver.

When I try to add a new Message object the related users are left null

Message message = new Message();
message.text = InputText; // string
message.Sender = Sender; // User object
message.Receiver = Receiver; // User object

context.AddToMessages(message);
context.BeginSaveChanges(new AsyncCallback((result) => 
{ 
    // Some code 
}));

Now the Sender and Receiver will be null. When I try to set a link before the BeginSaceChanges like this I get the error “InvalidOperationException: The context is not currently tracking the entity.”

context.AddToMessages(message);
context.AddLink(message, "Sender", message.Sender);
context.AddLink(message, "Receiver", message.Receiver);
context.BeginSaveChanges(new AsyncCallback((result) => 
{ 
    // Some code 
}));

How do I make sure the relations are created properly?

  • 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-04T20:03:42+00:00Added an answer on June 4, 2026 at 8:03 pm

    Thanks to Pratik I found the solution. I had to use attach the already existing users Sender and Receiver to the context first because they weren’t tracked (and added a if if they are on the second call). Then I add the message and use SetLink to set the link to both users (instead of AddLink)

    if(context.GetEntityDescriptor(message.Sender) == null)
        context.AttachTo("Users", message.Sender);
    if (context.GetEntityDescriptor(message.Receiver) == null)
        context.AttachTo("Users", message.Receiver);
    context.AddToMessages(message);
    context.SetLink(message, "Sender", message.Sender);
    context.SetLink(message, "Receiver", message.Receiver);
    context.BeginSaveChanges(new AsyncCallback((result) => 
    { 
        // Some code 
    }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following Situation, Server A sends some data (HTML form) to server B,
I have the following situation. Im getting data from an external system in the
I have the following situation: I have class User with the follwing properies :
I have the following situation: Three concrete service classes implement a service interface: one
I have the following situation: public abstract class A { private Object superMember; public
i have the following situation: one drawing layer (graphics object with lineTo, etc.) one
I have the following code in WCF service to throw a custom fault based
I have following situation. I have a class for accounts, each account has a
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have the following situation: On[t::shdw] Message[t::shdw,t,Foobar,Dork] -> t::shdw: Symbol t appears in multiple

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.