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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:49:39+00:00 2026-06-17T12:49:39+00:00

I am gathering data from a web-form with the code below: secondContact.FirstName = txtFirstNameContact2.Text;

  • 0

I am gathering data from a web-form with the code below:

secondContact.FirstName = txtFirstNameContact2.Text;
secondContact.LastName = txtlastNameContact2.Text;
secondContact.EmailAddress = txtEmailAddressContact2.Text;
secondContact.PhoneNumber = txtPhone1Contact2.Text + txtPhone2Contact2.Text + txtPhone3Contact2.Text;
if (!string.IsNullOrEmpty(rblContactTypeContact2.SelectedValue))
{
    secondContact.SecondaryContactTypeID = Convert.ToInt32(rblContactTypeContact2.SelectedValue);
}
secondContact.ContactPosition = 2;
secondContact.ProspectID = prospect.Id;

Sending the code to the repository to be saved with the code below (which it grabs the prospect.Id successfully):

if (prospect.Id != 0)
   {
    if (!string.IsNullOrEmpty(secondContact.FirstName) || !string.IsNullOrEmpty(secondContact.LastName) || !string.IsNullOrEmpty(secondContact.EmailAddress) || !string.IsNullOrEmpty(secondContact.PhoneNumber))
    {
        this.repository.SaveAltContact(prospect.Id, 2, secondContact);
    }
}

The repository trys to save the data:

public void SaveAltContact(int prospectID, int contactPosition, SecondaryContact contact)
{
    using (var context = new CoyleHomeBuyerEntities())
    {
        SecondaryContact currentAltContact = new Model.SecondaryContact();

        currentAltContact = (from sec in context.SecondaryContact
                             where sec.ContactPosition == contactPosition
                             where sec.ProspectID == prospectID
                             select sec).FirstOrDefault();

        if (currentAltContact == null)
        {
            context.AddToSecondaryContact(currentAltContact);
        }

        currentAltContact.FirstName = contact.FirstName;
        currentAltContact.LastName = contact.LastName;
        currentAltContact.EmailAddress = contact.EmailAddress;
        currentAltContact.PhoneNumber = contact.PhoneNumber;
        currentAltContact.SecondaryContactTypeID = contact.SecondaryContactTypeID;
        currentAltContact.ProspectID = prospectID;
        currentAltContact.ContactPosition = contactPosition;

        context.SaveChanges();
    }
}

It always fails after this line with a Null exception:

context.AddToSecondaryContact(currentAltContact);

I’m baffled, because I expect the query above to return a NULL value at this point. SecondaryContactID is set to be the primary key and to auto increment.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: entity

Can someone point me in the right direction as to why this is failing when trying to add a new row to the database?

  • 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-17T12:49:41+00:00Added an answer on June 17, 2026 at 12:49 pm

    Actually I got it to work by simply declaring the currentAltContact variable at the top and instantiating a new object only if there was a null record

    public void SaveAltContact(int prospectID, int contactPosition, SecondaryContact contact)
        {
            using (var context = new CoyleHomeBuyerEntities())
            {
                    SecondaryContact currentAltContact;
    
                currentAltContact = (from sec in context.SecondaryContact
                                     where sec.ContactPosition == contactPosition
                                     where sec.ProspectID == prospectID
                                     select sec).FirstOrDefault();
    
                if (currentAltContact == null)
                {
                    currentAltContact = new Model.SecondaryContact();
                    context.AddToSecondaryContact(currentAltContact);
                }
    
                currentAltContact.FirstName = contact.FirstName;
                currentAltContact.LastName = contact.LastName;
                currentAltContact.EmailAddress = contact.EmailAddress;
                currentAltContact.PhoneNumber = contact.PhoneNumber;
                currentAltContact.SecondaryContactTypeID = contact.SecondaryContactTypeID;
                currentAltContact.ProspectID = prospectID;
                currentAltContact.ContactPosition = contactPosition;
    
                context.SaveChanges();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After gathering data from a web service, I'm trying to pull out only those
I am gathering data from youtube's gdata API and would like to use the
So I'm trying to automate a pretty tedious data gathering process from hundreds of
I am gathering data from a website. I estimate to get 10.000 datapoints (time
I'm using a PHP array that is gathering data from a mysql database. I'm
The Story There is a writer thread, periodically gathering data from somewhere (in real-time,
I'm working with gathering data from a biological monitoring system. They need to know
I mean how google analytics gathering data from client side. My guess is that
I am going to implement an application that is gathering data from Android device.
Context : I'm trying to create a pie chart using jqPlot, gathering data from

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.