When trying to print out all my users stored in UDbTable I get the error named in the title. It builds well until the moment I try to open the index that should contain the list.
What am I doing wrong?
Here's my code so far:
public class AdminController : BaseController
{
private UserContext context;
// GET: Admin
[AdminMod]
public ActionResult Index()
{
SessionStatus();
if ((string)System.Web.HttpContext.Current.Session["LoginStatus"] != "login")
{
return RedirectToAction("Index", "Login");
}
var user = System.Web.HttpContext.Current.GetMySessionObject();
UserData u = new UserData
{
Username = user.Username,
Level = user.Level,
};
List<UDbTable> users = context.Users.ToList(); //program dies here
return View("Index", users);
}
}
Here's my UserContext:
public class UserContext : DbContext
{
public UserContext() :
base("name=WebApplication1")
{
}
public virtual DbSet<UDbTable> Users { get; set; }
}
Here's my UDbTable:
public class UDbTable
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[Display(Name = "Username")]
[StringLength(30, MinimumLength = 5, ErrorMessage = "Username cannot be longer than 30 char")]
public string Username { get; set; }
[Required]
[Display(Name = "Password")]
[StringLength(50, MinimumLength = 8, ErrorMessage = "Password short, >8 char")]
public string Password { get; set; }
[Required]
[Display(Name = "Email Address")]
[StringLength(30)]
public string Email { get; set; }
[DataType(DataType.Date)]
public DateTime LastLogin { get; set; }
[StringLength(30)]
public string LasIp { get; set; }
public URole Level { get; set; }
}