Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
How to modify Random().Next() to Autoincrementing

I am doing an ASP.NetCore MVC Project.

Following is the code I am using to insert the primary key of the table 'ImageFile'.
(It has attributes like: Id, UserID, ImageName, Size, URl etc. UserId is a foreign key).

ImageFile imageFile = new ImageFile();
imageFile.Id = new Random().Next();

This just inserts a random number into the Id field of the table.
Ex:

ID UserId ImageName
1513570791 2 image1.png
1714580687 2 image2.png
5909420604 2 image3.png

How can I modify the above code snippet to insert an auto-incrementing value to the table ?
Ex:

ID UserId ImageName
1 2 image1.png
2 2 image2.png
3 2 image3.png

Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

 ImageFile imageFile = new ImageFile(); imageFile.Id = new ValueGeneratedOnAdd();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!