您的位置:首页 > 其它

EF CodeFirst学习笔记003--如何创建表

2014-10-23 09:26 567 查看
参考:

/article/4862877.html

webconfig中修改:

<connectionStrings>
<add name="BlogEntities" connectionString="server=gwsite4;database=EfStudy;integrated security=false;User ID=sa;Password=teamplate" providerName="System.Data.SqlClient"/>
</connectionStrings>

我的测试环境没用MVC,用的普通aspx页面:

运行Step001页面时,就会自动将你的业务类创建到远程的数据库上了.

public partial class Step001 : System.Web.UI.Page
{
BlogEntities db = new BlogEntities();
protected void Page_Load(object sender, EventArgs e)
{
foreach (Blog b in db.Blogs)
{
Response.Write(b.Title + "*");
}
Response.Write("#");
}

protected void btnAdd_Click(object sender, EventArgs e)
{
Blog b = new Blog();
b.Title = "Snow test";
b.BlogTypeId = 1;
b.CreateTime = DateTime.Now;
db.Blogs.Add(b);
db.SaveChanges();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: