Verified that SQL Express was running.
Using Visual Studio 2015
/App_code/departments.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace cfsEnergyManagement.App_Code
{
public class department
{
public string ID { get; set; }
public string title { get; set; }
public List<utilityUse> utilityUse { get; set; }
}
}
/App_code/utilityUse.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace cfsEnergyManagement.App_Code
{
public class utilityUse
{
public string utilityID { get; set; }
public string title { get; set; }
public string year { get; set; }
public string month { get; set; }
public int kiloWattHour { get; set; }
public int tonHour { get; set; }
public int kiloPoundsHour { get; set; }
public int netCost { get; set; }
}
}
/App_Code/dbContext.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace cfsEnergyManagement.App_Code
{
public class cfsEnergyDb: DbContext
{
public DbSet<department> departments { get; set; }
public DbSet<utilityUse> utilityUses { get; set; }
}
}
dbContextRun.cs
namespace cfsEnergyManagement.App_Code
{
public class dbContextRun
{
cfsEnergyDb CfsEnergyDb = new cfsEnergyDb();
}
}
Connection String: web.config
<connectionStrings>
<add name="cfsEnergyDb" connectionString="server=SQLEXPRESS;integrated security=SSPI;database=cfsEnergy" providerName="System.Data.SqlClient" />
</connectionStrings>
Because you are not instantiating cfsEnergyDb class. Entity framework only and only create database when you will try to access any data for the first time from database table(any db queries). So try to access data from table and EF will create all the tables for you in database(specified in connection string).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.