Error trying to generate Scaffolding

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; }
    }
}

But when trying to execute the error is returned:

Could someone tell me why?

    
asked by anonymous 29.11.2016 / 18:26

1 answer

2

The error is quite clear. It says your model does not have a Key set, meaning VS does not understand that its CombustivelModels class has a primary key. The reason for this might be some things, like:

  • You are not using the [Key] or Fluent API attribute;
  • The template name does not follow the ClassName + Id or just Id

We can see from your code that this is not the problem because you are using the [Key] Attribute.

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

    
29.11.2016 / 19:11