I have created my connection string and it seems to be connecting without error. I am simply trying to output the various IDs, but it’s acting like there’s nothing there!
The table is full of records… It doesn’t output any error, either. How can I even debug something like this?
Model:
namespace MvcApplication1.Models
{
public class Directory
{
public int ID { get; set; }
public bool DELETED { get; set; }
public Guid CREATED_BY { get; set; }
public DateTime DATE_ENTERED { get; set; }
public Guid MODIFIED_USER_ID { get; set; }
public DateTime DATE_MODIFIED { get; set; }
public Guid USER_ID { get; set; }
public Guid BRANCH_ID { get; set; }
}
public class MyDbContext : DbContext
{
public DbSet<Directory> Directories { get; set; }
}
}
View:
@model IEnumerable<MvcApplication1.Models.Directory>
@foreach (var item in Model) {
<tr>
<td>
@item.ID
</td>
</tr>
}
Controller:
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
private Models.MyDbContext db = new Models.MyDbContext();
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View(db.Directories.ToList());
}
}
}
Thanks to all for your help. I figured it out. I was using the wrong table name to start with, but then I also needed to add
Database.SetInitializer<Models.MyDbContext>(null);to my global.asax…