zoukankan      html  css  js  c++  java
  • ASP.NET MVC 学习之路-5

    本文在于巩固基础

    数据库开发模式:

    1.数据库优先开发模式

    2.模型优先开发模式

    EntityFramework学习之一

    最简单的一个案例

    第一步创建模型

     public class Student
        {
            [Key]
            public int StudentId { get; set; }
    
            public string StudentName { get; set; }
            public string Sex { get; set; }
            public int Age { get; set; }
        }

    第二步创建上下文类

     public class EntitiesContext:DbContext
        {
            public EntitiesContext()
                : base("name=ConnString")//即连接字符串
            {
            }
    
            public DbSet<Student> Students { get; set; }
        }

     第三步配置连接字符串

    <connectionStrings>
         <add name="ConnString" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Initial Catalog=MyDB;Integrated Security=true;"/>
      </connectionStrings>

    第四步利用上下文来获取数据

     private EntitiesContext _db=new EntitiesContext();
            public ActionResult Index()
            {
                return View(_db.Students.ToList());
            }

    数据库中自动生成的表

  • 相关阅读:
    PHP 对Memcache的使用实例
    PHP Memcache 扩展安装
    Effective STL 读书笔记
    windows下安装和使用scrapy
    使用insert ignore来避免向数据库重复插入数据
    2017年末
    归并排序
    二叉树的中序遍历
    正则表达式
    tinymq学习小结
  • 原文地址:https://www.cnblogs.com/jixinyu/p/4318506.html
Copyright © 2011-2022 走看看