Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

0

 ImageFile imageFile = new ImageFile(); imageFile.Id = new ValueGeneratedOnAdd();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda