Friday 23 December 2022

The entity type 'Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup' requires a primary key to be defined

 In order to fix this, simply put

[NotMapped]

above the SelectList property within the model .cs file:

[NotMapped]
public SelectList SiteList { get; set; }

This prevents EntityFramework from mapping the list to the model. Since it's not part of the model database, it doesn't require a primary key.

===========================================================

public class UserSearchModel

    {

        [Key]

        public Int64 ID { get; set; }

        public string UserName { get; set; }

        public string FirstName { get; set; }

        public string SecondName { get; set; }

        public string Password { get; set; }

        [NotMapped]

        public string ConfirmPassword { get; set; }

        public string RoleName { get; set; }

        public Int64 RoleId { get; set; }

        [NotMapped]

        public IEnumerable<SelectListItem> RoleList { get; set; }

        [NotMapped]

        public List<Int64> LocationId { get; set; }

        [NotMapped]

        public List<SelectListItem> Locations { get; set; }

        public bool IsActive { get; set; }

        public string? Notes { get; set; }

        [Display(Name ="Enter text for search")]

        [NotMapped]

        public string SearchText { get; set; }


    }

No comments:

Post a Comment