码迷,mamicode.com
首页 > Web开发 > 详细

MVC3入门试练----模型

时间:2014-12-20 18:22:29      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:命名   public   

模型类(例如: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

MVC3入门试练----模型

标签:命名   public   

原文地址:http://962410314.blog.51cto.com/7563109/1592014

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!