sportdog

导航

 

参考:

http://www.cnblogs.com/Wayou/archive/2012/09/20/EF_CodeFirst.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();
        }
    }

 

posted on 2014-10-23 09:26  sportdog  阅读(256)  评论(0编辑  收藏  举报