模型类(例如:School.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//需要引用的命名空间
using System.Data.Entity;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MvcApplication3.Models
{
/// <summary>
/// 模型类,School对应着数据库中的名字
/// 这个类中的属性对应着数据库里的字段名称
/// </summary>
public class School
{
//指定主键,不要相信mvc的约定
[Key]
public virtual int s_id { get; set; }
public virtual int s_name { get; set; }
public virtual int s_date { get; set; }
public virtual SchoolType SchoolType{get;set;}
}
/// <summary>
/// 数据库上下文
/// 类负责在数据库中获取,存储,更新,处理 School
/// </summary>
public class SchoolDBContext : DbContext
{
public DbSet<School> Schools { get; set; }
}
}
=======================添加控制器
本文出自 “程序猿的家--Hunter” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1592014
原文地址:http://962410314.blog.51cto.com/7563109/1592014