One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'SelectListItem' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'SelectListItems' is based on type 'SelectListItem' that has no keys defined.
public class Country
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Display(Name = "Country Name")]
public string Name { get; set; }
}
public List<SelectListItem> country = new List<SelectListItem>();
public List<SelectListItem> Country
{
get
{
country.Clear();
using (UsersContext DB = new UsersContext())
{
var cat = DB.Countries;
foreach (var q in cat)
{
country.Add(new SelectListItem() { Text = q.Name, Value = q.Id.ToString() });
}
return country;
}
}
}
But I have already declared [Key]
. What I have to do else?