另类的Linq To Sql——CoolEntity开始开发(二) 编写实体类Mapping表

本文介绍了如何在Linq To Sql的替代方案CoolEntity中编写实体类和Mapper类,以实现数据库表与类的映射。通过创建Entities和Mappers文件夹,定义Role和User类,并重写GetTableInfo和MapProperties方法来指定表与类的关系。文章以具体的代码示例展示了Mapper类的编写过程,并总结了Mapper类的作用和映射规则。
摘要由CSDN通过智能技术生成

接着上一次没有做完的DemoData控制台应用程序,开始

编写实体类

新建Entities文件夹,新建类如下图
这里写图片描述
实体类代码如下
Role(角色)类
Role类
User(用户)类
User类

编写Mapper类

新建Mappers文件夹,创建如下Mapper类
mappers
Role的Mapper类

using CoolEntity.Mapping;
using CoolEntity.Mapping.Commom;
using DemoData.Entities;

namespace DemoData.Mappers
{
    /// <summary>
    /// 角色的Mapper类
    /// </summary>
    internal class RoleMapper : EntityMapper<Role>
    {
        /// <summary>
        /// 获取所Mapping的Table
        /// </summary>
        /// <returns>所Mapping的Table信息</returns>
        protected override ITableInfo GetTableInfo()
        {
            return base.GetTableInfo("Roles", "dbo");
        }
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值