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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:18:39+00:00 2026-06-15T05:18:39+00:00

I’m not sure how to exactly word my question which is probably why I

  • 0

I’m not sure how to exactly word my question which is probably why I cannot find an example of this anywhere. I’m playing around with MVC4 & EF5 (Web API too) but I’m not sure how to proceed with the Model as I’ve never really had to do much with them before. I’m doing something around the Periodic Tablet of Elements and I want to make it so that I have a list built for an element with it’s electron configuration. However, I’d like to have it just auto number based on the input order. How can I tell EF to auto-increment a field? Basically like a primary key field without that limitation behind it. Here’s what I have so far – I’m just not sure how to proceed:

public class Elements
{
    public int ElementID { get; set; }
    public string Name { get; set; }
    public int AtomicNumber { get; set; }
    public string Symbol { get; set; }
    public virtual Categories Category { get; set; }
    public virtual States State { get; set; }
    public virtual Occurences Occurence { get; set; }
    public virtual ICollection<Configurations> Configuration { get; set; }
}

public class Categories 
{
    public int CategoryID { get; set; }
    public string CategoryName { get; set; }
}

public class States
{
    public int StateID { get; set; }
    public string StateName { get; set; }
}

public class Occurences
{
    public int OccurenceID { get; set; }
    public string OccurenceName { get; set; }
}

public class Configurations
{
    public int ConfigurationID { get; set; }
    public int Order { get; set; }
    public int Value { get; set; }
}

Looking above what I’d like is for anytime a value is added to Configurations.Order the value starts at 1 and increases with each new ‘row’ but only for that specific ElementID.

Does that make sense? I was looking at using Data Annotations but I couldn’t find anything that matched other than a Key Field but that’d make each Order a unique number – which I don’t want. I feel like I’m not expressing this correctly because of all the stuff I’ve been looking at to figure it out, so here’s a picture! yay!

enter image description here

This very well could be something that is better off from a programmatic standpoint. Even though this data changes once in a blue moon, I wanted to try and do it through EF if possible just so I know how.

Thanks a ton in advance. Also, if you see any other glaring errors, by all means let me know 🙂 I rarely get to work with this side of web dev so I’m sure there’s ways to do things better.

  • 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-15T05:18:41+00:00Added an answer on June 15, 2026 at 5:18 am

    How can I tell EF to auto-increment a field?

    You can’t. Not even for a simple auto-incrementing primary key. Let alone for a field that should increment in relation to other values.

    The HasDatabaseGeneratedOption mapping method is not a way to tell EF how to generate key values. It tells EF if and how the database generates values for properties, so EF knows how to respond to that.

    So you either have to generate the order numbers in code, or let the database do it (by a trigger, or by mapping CUD actions on Configurations to stored procedures) and tell EF that the database computes the values by HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed) in the configuration of the Order property.

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

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.