I have a table in my EF model that is not creating within the database on access.
The table name is "sites" and is linked to a parent table by the use of a foreign key called "CompanyId".
I am attmempting to list all the sites that belong to a specific company (the company table is linked to the ApplicationUser)
I would expect that when i call the database for a list of the sites that it will be created. However i just receive an error that states the table does not exist
My model for the two tables is as follow
public class Company
{
[Key]
public int CompanyId { get; set; }
public string CompanyName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string PostCode { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string TelephoneNumber { get; set; }
public string Email { get; set; }
public virtual IQueryable<Site> Sites { get; set; }
}
public class Site
{
[Key]
public int SiteId { get; set; }
public int CompanyId { get; set; }
public string SiteName { get; set; }
public string Url { get; set; }
}
and my controller
public ActionResult Index()
{
//get the user details
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentuser = manager.FindById(User.Identity.GetUserId());
// search
var company = currentuser.Companies;
var sites = company.Sites;
if (sites == null)
{
sites = db.Sites.Where(c => c.CompanyId == company.CompanyId);
return View(sites.ToList());
}
return View(company.Sites.ToList());
}
DbSetfor that table in the context?