• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

173
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.

about 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

 ImageFile imageFile = new ImageFile(); imageFile.Id = new ValueGeneratedOnAdd();
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda