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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:13:54+00:00 2026-06-06T16:13:54+00:00

I have a new ParameterPart entity that is related to a new InputOutputMap. The

  • 0

I have a new ParameterPart entity that is related to a new InputOutputMap. The InputOutputMap has several InputStates that I pull from the database and I need to associate with the InputOutputMap. How do I save this chain to the database using MVC and WCF Data services? I am using the following code (being called through an ajax call, context is only being set in the first call in the constructor) but am getting several issues:

  • When I use AddLink (as shown below), I am able to add data the first time I try it (irrespective of how many inputstates I have to associate). If however, the method is called again (through ajax), I am only able to add data if I am specifying one inputstate. If I have multiple inputstates, I get context is already tracking the relationship. Note that the method is being called using an ajax call.
  • I have tried using SetLink, AddRelatedObject and attach but everytime I am getting errors in the above scenario. Sometimes, the error is that context is already tracking the entity or the relationship. At other times, the context is not tracking the entity.
  • I didn’t get any benefit when I set the context in the method instead of the constructor.

    if (vm != null)
        {
            ParameterPart parameterPart = null;
    
            // Create a new parameter
            if (vm.PartNumberId == 0)
            {
                // Create an instance of ParameterPart
                parameterPart = new ParameterPart()
                {
                    Description = vm.ParameterDescription                        
                };
    
                // Save the ParameterPart into the database
                try
                {
                    ctx.AddToParameterParts(parameterPart);
                    ctx.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    throw;
                }
            }
            else
            {
                // Fetch the existing parameter
                parameterPart = new ParameterPart();
                parameterPart = (from pp in ctx.ParameterParts
                                 where pp.PartNumberId == vm.PartNumberId
                                 select pp).Single();
    
                // Update the ParameterPart from the vm
                parameterPart.Description = vm.ParameterDescription;
            }
    
            if (parameterPart != null)
            {
                if (vm.StateValues.Count > 0)
                {
                    InputOutputMap inputOutputMap = new InputOutputMap();
                    inputOutputMap.PartNumberId = parameterPart.PartNumberId;
    
                    ctx.AddToInputOutputMaps(inputOutputMap);
    
                    // Prepare a new InputOutputMap
                    foreach (var state in vm.StateValues)
                    {
                        if (state.InputStateId != 0)
                        {
                            // Fetch the inputstate
                            var inputState = (from i in ctx.InputStates
                                              where i.InputStateId == state.InputStateId
                                              select i).Single();
    
                            try
                            {
                                ctx.AddLink(inputOutputMap, "InputStates", inputState);
                                ctx.SaveChanges();
                            }
                            catch (System.Exception ex)
                            {
                                throw;
                            }
                        }                            
                    }
                }
            }
        }
    
  • 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-06T16:13:55+00:00Added an answer on June 6, 2026 at 4:13 pm

    The AddLink method was working as desired. I was getting an error due to a data issue.

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

Sidebar

Related Questions

I have a new service that I have written and need to register it
From my last question , I have new idea for database protection. The following
I have a project that stores several millions of domain names in database and
When we have new in C#, that personally I see only as a workaround
I have a web project that used to use Forms Authentication. I have new
I am attempting to bulk move my files to new folders that have new
I have a SQLite database that is created by reading some data in PDF
The Problem is that I have a web reference genereted from WSDL file. Now
i have new discovered Flex 4 and i think, that it is great, but
So I have a LongInt class that will have new definition for the +

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.