@XingdingCAO
2017-07-15T23:13:17.000000Z
字数 1651
阅读 2440
简易打分系统

表现层(UI:User Interface):对应以.aspx结尾的文件
业务逻辑层(BLL:Business Logic Layer):对应以.aspx.cs结尾的页面处理类和其他逻辑处理的类(例如:处理用户身份验证的类)
数据访问层(DAL:Data Access Layer):对应数据访问类,所有对数据库的操作都应该通过调用数据访问类的方法实现;而其对数据库的访问的方法实际离不开模型类和对应的继承自DbContext的类(使用EntityFramework)
模型类(Model):和数据库中的表一一对应,每个模板类都应该配有一个继承自DbContext的类(使用EntityFramework)
模板类(Model)不属于任何一层,因为其具有流动性不是固定于某一层的
DbContext的类):
//Model类namespace Vote.Models{using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Data.Entity.Spatial;[Table("Account")]public partial class Account{[Key][StringLength(10)]public string Username { get; set; }[Required][StringLength(10)]public string Password { get; set; }public int GroupID { get; set; }public bool IsLeader { get; set; }}}
//继承DbContext类namespace Vote.Models{using System;using System.Data.Entity;using System.ComponentModel.DataAnnotations.Schema;using System.Linq;public partial class AccountModel : DbContext{public AccountModel(): base("name=AccountConnect"){}public virtual DbSet<Account> Accounts { get; set; }protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Entity<Account>().Property(e => e.Username).IsFixedLength();modelBuilder.Entity<Account>().Property(e => e.Password).IsFixedLength();}}}
