首先介绍下公共对象类库下的公共对象类
这些对象的作用就是简化数据传递操作,因为它们能够包含数据,并且为该信息提供统一的封装方法。
ShoppingCartEntity(购物车)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ShoppingCartEntity
{
public int ShoppingCartID { set; get; }
public string CartGUID { set; get; }
public int Quantity { set; get; }
public int ProductID { set; get; }
public DateTime DateCreated { set; get; }
}
}
ProductEntity类

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ProductEntity
{
public int ProductID { set; get; }
public int ProductCategoryID { set; get; }
public ProductCategoryEntity ProductCategory { set; get; }
public string ProductName { set; get; }
public string ProductImageName { set; get; }
public string ProductDescription { set; get; }
public int Quantity { set; get; }
public Decimal ProductPrice { set; get; }
public ProductEntity()
{
this.ProductCategory = new ProductCategoryEntity();
}
}
}
ProductCategoryEntity(产品种类)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ProductCategoryEntity
{
public int ProductCategoryID { set; get; }
public string ProductCategoryName { set; get; }
}
}
OrdersEntity(订单)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class OrdersEntity
{
public int OrderID { set; get; }
public int EndUserID { set; get; }
public EndUserEntity EndUser { set; get; }
public string TransactionID { set; get; }
public DateTime OrderDate { set; get; }
public AddressEntity ShippingAddress { set; get; }
public int OrderStatusID { set; get; }
public Decimal ShippingTotal { set; get; }
public OrderDetailsEntity OrderDetails { set; get; }
public Decimal SubTotal { set; get; }
public Decimal OrderTotal { set; get; }
public Decimal Tax { set; get; }
public CreditCardEntity CreditCard { set; get; }
public DateTime ShipDate { set; get; }
public string TrackingNumber { set; get; }
public OrdersEntity()
{
this.EndUser = new EndUserEntity();
this.ShippingAddress = new AddressEntity();
this.CreditCard = new CreditCardEntity();
this.OrderDetails = new OrderDetailsEntity();
}
}
}
OrderDetailsEntity(详细订单)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class OrderDetailsEntity
{
public int OrderDetailID { set; get; }
public int OrderID { set; get; }
public int ProductID { set; get; }
public ProductEntity[] Products { set; get; }
public int Quantity { set; get; }
}
}
Enums类(用户类别)

Code
using System;
using System.Collections.Generic;
using System.Text;
namespace Shop.Common
{
public class Enums
{
public enum EndUserType
{
CUSTOMER = 1,
ADMINISTRATOR = 2
}
}
}
EndUserTypeEntity类(用户类别)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class EndUserTypeEntity
{
public int EndUserTypeID { set; get; }
public string EndUserName { set; get; }
}
}
EndUserEntity(用户)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
/// <summary>
/// 用户实体类
/// </summary>
public class EndUserEntity
{
public int EndUserID { get; set; }
public int EndUserTypeID { set; get; }
public string UserName { set; get; }
public AddressEntity UserAddress { set; get; }
public int AddressID { set; get; }
public ContactInformationEntity UserContactInformation { set; get; }
public int ContactInformationID { set; get; }
public string Password { set; get; }
public bool IsSubscribed { set; get; }
public EndUserEntity()
{
this.UserAddress = new AddressEntity();
this.UserContactInformation = new ContactInformationEntity();
}
}
}
CreditCardEntity类(信用卡)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class CreditCardEntity
{
public AddressEntity Address { set; get; }
public string CardType { set; get; }
public int ExpMonth { set; get; }
public int ExpYear { set; get; }
public string Number { set; get; }
public string SecurityCode { set; get; }
}
}
ContactInformationEntity类 (联系信息)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ContactInformationEntity
{
public int ContactInformationID { set; get; }
public string Phone { set; get; }
public string Phone2 { set; get; }
public string Fax { set; get; }
public string Email { set; get; }
}
}
AddressEntity类 (用户地址信息)

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class CreditCardEntity
{
public AddressEntity Address { set; get; }
public string CardType { set; get; }
public int ExpMonth { set; get; }
public int ExpYear { set; get; }
public string Number { set; get; }
public string SecurityCode { set; get; }
public CreditCardEntity()
{
this.Address = new AddressEntity();
}
}
}
从上看出基本上一张数据库表对应一个公共对象类,相信大家一扫都能明白。
以前做法就是编写一个公共对象类紧接着将它和对数据库操作的类放在一起的,不像这个系统放在一起,另外我也是不会在公共对象类中使用另外一种公共数据类型的,你看这里EndUserEntity类引用了AddressEntity类和ContactInformationEntity类(这样还要注意编写构造函数,这里的类不是静态的所以要记得new一个,在构造函数中完成它),要是以前设计是不会放进去的,我会分别构造这三个类。我觉得这样只用一个类就涵盖了所有的数据很方便,但是数据类型很复杂,如果考虑到在客户端调用webservice存储数据肯定就复杂了,不知道json能不能传这样的复杂数据。反正这样设计可能使设计思路更清晰,代码简洁了。可以在这个类库下多加几个文件,一个文件中放入一个系统模块所需要的公共对象类,我想在扩展时候,思路更清晰了。
上面有一个地方要注意一下就是smallmoney数据类型在数据对象变为Decima,以前会用double.不知道Decima会不会比double好?
不知道大家的设计思路是怎样的,我希望大家说出自己的设计的思路,大家共同学习嘛,也希望高人指点。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述