zoukankan      html  css  js  c++  java
  • EF CodeFirst学习笔记003--如何创建表

    参考:

    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();
            }
        }
    
  • 相关阅读:
    stl-序列式容器
    BFS
    Hash
    二分法
    草稿1
    红黑树的左旋、右旋和颜色变换
    动态规划
    自动驾驶-安全
    二叉树

  • 原文地址:https://www.cnblogs.com/sportdog/p/4044978.html
Copyright © 2011-2022 走看看