我是Entityframework.新嘗試使用CodeFirst方法entityFramework創建數據庫。我有我的代碼在DAL層的位置:在EntityFramework-CodeFirst方法上未創建數據庫
[Table("Category")]
public class Category
{
[Key]
public int CategoryId { get; set; }
[Required]
[Column(TypeName="varchar")]
[StringLength(200)]
public string CategoryName { get; set; }
}
public class DatabaseContext:DbContext
{
public DatabaseContext()
: base("DbConnection")
{
//Added the following but still it doesnt work
//Database.SetInitializer<DatabaseContext>(new CreateDatabaseIfNotExists<DatabaseContext>());
}
public DbSet<Category> Categories { get; set; }
}
連接字符串中dal層App.config文件
<connectionStrings>
<add name="DbConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=dbPdtCgry;uid=admin;password=admin123;"
providerName="System.Data.SqlClient"></add>
在SQL Server這不會創建數據庫management.But在App_Data中創建了DbConnection Log file & mdf file
,我可以添加,更新和刪除數據。
我在這裏想念什麼?
感謝設置'Server = localhost \ SQLserverInstanceName'解決了問題 – ksg