DotNetNext / SqlSugar

.Net aot ORM Fastest ORM Simple Easy VB.NET Sqlite orm Oracle ORM Mysql Orm 虚谷数据库 postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping
https://www.donet5.com/Home/Doc
MIT License
5.27k stars 1.33k forks source link

PG 字段组数类型Select查询的问题? #1094

Closed zanderzhg closed 1 year ago

zanderzhg commented 1 year ago

实体

[SugarTable("sys_role")]
public class SysRoleEntity : BaseEntity
{
    #region Properties

    [SugarColumn(ColumnDescription = "角色名称")]
    public string Name { get; set; } = string.Empty;

    [SugarColumn(ColumnDescription = "角色绑定的菜单Ids", IsArray = true, ColumnDataType = "int8[]")]
    public long[]? MenuIds { get; set; }

    [SugarColumn(ColumnDescription = "描述")]
    public string? Description { get; set; }

    public bool Enabled { get; set; } = true;

    #endregion Properties
}

直接查询实体能够查出来

public async Task<SysRoleEntity> TestAsync(long id)
    {
        return await _roleRepository.AsQueryable()
            .SingleAsync(i => i.Id == id);
    }

结果

"data": {
    "name": "测试角色",
    "menuIds": [
      8,
      9
    ],
    "description": "1",
    "enabled": true,
    "id": 2,
    "createBy": "管理员",
    "createTime": "2022-11-07 11:13:02",
    "modifyBy": null,
    "modifyTime": null,
    "remark": null
  },

使用Select<>() menuIds返回null dto

public class UpdateRole
{
    public long Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public long[]? MenuIds { get; set; }
    public bool Enabled { get; set; }
}

    public async Task<UpdateRole> GetByIdAsync(long id)
    {
        return await _roleRepository.AsQueryable()
            .Select<UpdateRole>()
            .SingleAsync(i => i.Id == id);
    }
"data": {
    "id": 2,
    "name": "测试角色",
    "description": "1",
    "menuIds": null,
    "enabled": true
  },
DotNetNext commented 1 year ago

实体要加上特性 IsArray=true

zanderzhg commented 1 year ago

实体要加上特性 IsArray=true

收到,原来DTO也要加

DotNetNext commented 1 year ago

主要是 json和array都可以存数组 所以没作自动判断让用户指定