3C数码商城——三层架构Model层

首先我们需要在Model里创建类库有几张表最好创建几个类库

根据sql表示,里面包含了两张表ProductCategory(产品类别表)和Product(产品表)

--产品类别表
create table ProductCategory 
(
	Id	int	primary key identity(1,1), --主键,标识列	主键Id			
	Name	nvarchar(16) not null	--不能为空	类别名称
)


--产品表
create table Product 
(
	Id	int primary key identity(1,1),	--主键,标识列	主键Id
				
	ProductName	nvarchar(32) not null,	--不能为空		产品名称
				
	MarketPrice	decimal(16,2) not null,	--不能为空		市场价
			
	SellingPrice	decimal(16,2) not null,	--不能为空	售价
	CategoryId	int	references ProductCategory(Id), 	--外键,不能为空	类别Id
	Introduction	nvarchar(128) not null,	--不能为空	产品介绍
	IsOnSale	bit not null,	--不能为空	是否上架
	AddTime datetime default getdate() not null--添加时间
)

 那么我们就在Model中创建ProductCategory(产品类别表)和Product(产品表)

并对该数据进行封装

Product.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    /// <summary>
    /// 产品表
    /// </summary>
    public class Product
    {   
        /// <summary>
        /// 主键Id
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; }
        /// <summary>
        /// 市场价
        /// </summary>
        public double MarketPrice { get; set; }
        /// <summary>
        /// 售价
        /// </summary>
        public double SellingPrice { get; set; }
        /// <summary>
        /// 类别Id
        /// </summary>
        public int CategoryId { get; set; }
        /// <summary>
        /// 产品介绍
        /// </summary>
        public string Introduction { get; set; }
        /// <summary>
        /// 是否上架
        /// </summary>
        public int IsOnSale { get; set; }
        /// <summary>
        /// 添加时间
        /// </summary>
        public DateTime AddTime { get; set; }
    }
}

 ProductCategory.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    /// <summary>
    /// 产品类别表
    /// </summary>
    public class ProductCategory
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 类别名称
        /// </summary>
        public string Name { get; set; }
    }
}

 特别注意:1、新建的类库中不会进行引用需手动添加public

                    2、封装的类型一定不能搞错,如时间用datetime

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值