日期:2014-05-17 浏览次数:20459 次
public class TestTableContext : DbContext
{
public TestTableContext(string databaseName):base(databaseName){}
public DbSet<TestTable> TestTables { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TestTable>().ToTable("Table1");
//modelBuilder.Configurations.Add(new TestTableMap());
}
}
static void Main(string[] args)
{
TestTable tt = new TestTable() { Name = "haha", age = 25 };
using (var context = new TestTableContext("ContextString"))
{
/*这里有问题
/*这里如果放开注释插入数据,会在SQLServer中新建一个数据库和一张表,并且插入数据,一切正常
/*这里如果注释掉,就是不插入数据,就不会创建数据库和表。*/
//context.TestTables.Add(tt);
context.SaveChanges();
}
Console.ReadKey();
}