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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:08:45+00:00 2026-05-18T01:08:45+00:00

We have an MVC application that creates entity models and stores them in a

  • 0

We have an MVC application that creates entity models and stores them in a session. Later on, we want to commit these to the database. Just trying to do a

db.Attendees.AddObject(attendee);

throws the error

The EntityKey property can only be set when the current value of the property is null.

The entity key is just a simple type of long and is an identity column in the database. What are we missing? This seems like such a simple thing to do? In order to get things to work, we have had to create a copy of the object and then save the copy. Can you not put entity framework models into session, bring them back out, and then save them?

Here’s the Attendee description in the Entity Framework model…it is hitting a SQL Server 2008 DB

[EdmEntityTypeAttribute(NamespaceName="Model", Name="Attendee")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class Attendee : EntityObject
{
    #region Factory Method

    /// <summary>
    /// Create a new Attendee object.
    /// </summary>
    /// <param name="attendeeID">Initial value of the AttendeeID property.</param>
    /// <param name="firstName">Initial value of the FirstName property.</param>
    /// <param name="lastName">Initial value of the LastName property.</param>
    /// <param name="email">Initial value of the Email property.</param>
    /// <param name="createdBy">Initial value of the CreatedBy property.</param>
    /// <param name="createdOn">Initial value of the CreatedOn property.</param>
    /// <param name="modifiedBy">Initial value of the ModifiedBy property.</param>
    /// <param name="modifiedOn">Initial value of the ModifiedOn property.</param>
    public static Attendee CreateAttendee(global::System.Int64 attendeeID, global::System.String firstName, global::System.String lastName, global::System.String email, global::System.String createdBy, global::System.DateTime createdOn, global::System.String modifiedBy, global::System.DateTime modifiedOn)
    {
        Attendee attendee = new Attendee();
        attendee.AttendeeID = attendeeID;
        attendee.FirstName = firstName;
        attendee.LastName = lastName;
        attendee.Email = email;
        attendee.CreatedBy = createdBy;
        attendee.CreatedOn = createdOn;
        attendee.ModifiedBy = modifiedBy;
        attendee.ModifiedOn = modifiedOn;
        return attendee;
    }

    #endregion
    #region Primitive Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int64 AttendeeID
    {
        get
        {
            return _AttendeeID;
        }
        set
        {
            if (_AttendeeID != value)
            {
                OnAttendeeIDChanging(value);
                ReportPropertyChanging("AttendeeID");
                _AttendeeID = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("AttendeeID");
                OnAttendeeIDChanged();
            }
        }
    }
    private global::System.Int64 _AttendeeID;
    partial void OnAttendeeIDChanging(global::System.Int64 value);
    partial void OnAttendeeIDChanged();
  • 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-18T01:08:45+00:00Added an answer on May 18, 2026 at 1:08 am

    You should be adding, not attaching, the new objects.

    Update If you get the same error when you AddObject, then you need to make sure the StoreGeneratedPattern in SSDL is set to Identity. The designer should do this for you if your DB is set up correctly and your provider supports it.

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

Sidebar

Related Questions

No related questions found

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.