I have method in repo, to get all data from database table.
Here is Model
public partial class User
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public User()
{
this.Roles = new HashSet<Role>();
}
[Key]
public int Id { get; set; }
public string Name { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Role> Roles { get; set; }
}
Here is repo code
public List<User> GetUsers()
{
using (var ctx = new HomstersTestDBEntities())
{
var items = ctx.Users.ToList();
return items;
}
}
And Like there I call it in controller
public JsonResult GetUsers()
{
var users = _userrepo.GetUsers();
return Json(users.ToArray(), JsonRequestBehavior.AllowGet);
}
But when I run website I get this error on method calling
How I can fix it?