Error while trying to generate Scaffolding

Asked

Viewed 143 times

0

I’m trying to generate a Scaffolfing for the model below:

    namespace OneeWeb_v2.Models
{
    public class CombustivelModels
    {
        [Key]
        public int CombustivelId { get; set; }

        [Required]
        public decimal km_inicial { get; set; }
        [Required]
        public decimal km_final { get; set; }
        [Required]
        public decimal litros { get; set; }
        [Required]
        [DataType(DataType.Currency)]
        public decimal valor { get; set; }
    }
}

However when trying to execute the error is returned:

inserir a descrição da imagem aqui

Would anyone know why?

  • 1

    Sometimes it is necessary to perform a Build for scaffolding to work. Right-click on the project and click Build.

  • Perfect. It worked.

1 answer

2


The error is very clear. He says that his model does not have a Key defined, i.e., the VS did not understand that its class Combustivelmodels possess a key Primary. The reason for this can be some things, like:

  • You are not using the Attribute [Key]or Fluent API;
  • The model name does not follow the standardization of Classname + Id or only Id;

We can see in your code that this is not the problem, as you are using the Attribute [Key].

However, you must have added this attribute before giving Build system for the last time. If this is the case, just right-click on the solution and click on Build.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.