模型层(ORM):数据库中每一个表都在模型层创建一个类,一般情况类的名称和数据表名相同,如果数据库中表名为复数型式,一般模型层类名为单数。
表中的字段在类中建成属性。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HotelManager.Models { public class RoomType { int typeId; public int TypeId { get { return typeId; } set { typeId = value; } } string typeName; public string TypeName { get { return typeName; } set { typeName = value; } } decimal price; public decimal Price { get { return price; } set { price = value; } } bool addBed; public bool AddBed { get { return addBed; } set { addBed = value; } } decimal bedPrice; public decimal BedPrice { get { return bedPrice; } set { bedPrice = value; } } string remark; public string Remark { get { return remark; } set { remark = value; } } } }