2

I Trying to insert the data into Database By using entity framework but it throwing error following An error occurred while updating the entries. See the inner exception for details.

Code is Here

public int InsertUserData(UserDetail userDetail, BusinessObjects objects)
    {
        try
        {
            UserCredential objCredentials = newPersonEntity.UserCredentials
            .First(cd => cd.UserName == objects.UserName);
            objCredentials.Status = objects.Status;
            newPersonEntity.UserDetails.Add(userDetail);
            int result=newPersonEntity.SaveChanges();
            return result;
        }
        catch (Exception ex)
        {  
            CatchError(ex);
            return 3;
        }


    }

Can Any One Tell what mistake i did ?

4
  • What is the inner exception? Probably a foreign key issue. Commented Dec 24, 2015 at 4:57
  • @JRLambert Already Foreign key value available in Primary key Table Commented Dec 24, 2015 at 5:04
  • Ok, but what does the inner exception say? Commented Dec 24, 2015 at 5:05
  • ThankYou For response guys I used One column as primary key which is the inner exception i solved it Commented Dec 24, 2015 at 5:17

1 Answer 1

1

As i undestand your code snipped correctly, you don't need to perform operations with objCredentials. Or if you want to change its status, you must call

newPersonEntity.UpdateObject(objCredentials);

And the only reason, why you cannot save changes is incorrect userDetail object fields values. Check that all required fields filled correclty and don't conflict with existing key values, stored in dataBase

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.