Problem with keys in EF mvc5 asp .net

0

I have defined the keys in each of those entities with the attribute [key] as you can see in the photo, apart from that the namespace is imported "using System.ComponentModel.DataAnnotations;" and when creating controllers this happens.

for this case, the traveling class is defined as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace OsAgenciaUSBT.Models
{
    public class Viajero
    {
        [key]
        public int IdViajero { get; set; }
        public string tipoViajero { get; set; }
        public string nombres { get; set; }
        public string Apellidos { get; set; }
        public int telefono { get; set; }

        [DataType(DataType.Date)]
        public DateTime Update { get { return DateTime.Now; } }


        public virtual ICollection<Venta> Venta { get; set; }
    }
}
    
asked by Sergio Bedoya 23.11.2017 в 22:43
source

1 answer

1

I notice that the attribute you use is key with a k lowercase. That is not right. The attribute you must use is System.ComponentModel.DataAnnotations.KeyAttribute , or simply Key (capitalized).

It is possible that you accidentally created a keyAttribute class somewhere in your project, and now you are using that attribute in the wrong way. Search where this confusing class goes and eliminate it to avoid more problems. (In fact, in your screenshot I can see the class keyAttribute.cs in your second tab. Eliminate it!)

    
answered by 23.11.2017 в 23:06