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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:35:42+00:00 2026-05-26T21:35:42+00:00

When adding a new record, the Key Attribute property does not save it’s value

  • 0

When adding a new record, the Key Attribute property does not save it’s value to the DB.

Further investigation showed me that it’s not in the SQL statement at all.

How can I add records with a value to the Key column?

EDIT:

This is the table:

CREATE TABLE `members` (
    `UniqueID` BIGINT(20) NOT NULL AUTO_INCREMENT,
    `MemberID` BIGINT(20) NOT NULL,
    PRIMARY KEY (`UniqueID`) USING BTREE,
    UNIQUE INDEX `Index_MemberID` (`MemberID`) USING BTREE);

This is the entity:

public class Member
{
    public long UniqueId { get; set; }
    [Key]
    public long MemberId { get; set; }
}
  • 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-26T21:35:43+00:00Added an answer on May 26, 2026 at 9:35 pm

    Your mapping is wrong:

    • You mark a property as key in your model whose corresponding column is not the primary key in the database.

    • You define your key property MemberId as database generated (bacuse it’s default and you don’t switch it off) but the column in the database isn’t an autoincrementing identity.

    The second problem you can solve by switching identity off:

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public long MemberId { get; set; }
    

    The first point leads to the behaviour that your supplied values of UniqueId in the model will be overwritten by the autoincrementing values in the database. If there will be other problems of mapping a key property to a non-key column with a unique column value constraint… I don’t know. At least I think that this is a unofficial, not supported usage of the key attribute and kind of mapping.

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

Sidebar

Related Questions

I have created one form that extends zend form. For Adding New Record it
I'm adding a new Row to a BindingSource that is Bound to a DataGridView
I want to update a column by adding a new value alongside the old
When adding new properties to classes, I find myself typing the same things over
I have situation where I need to change the order of the columns/adding new
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
I have a TreeView control on a form. I am dynamically adding new TreeNodes
I'm adding a new field to a list and view. To add the field
I'm currently adding some new extended classes to this code: foreach (BaseType b in
I'm updating a program and adding a new table to the database. The program

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.