Skip to content

Conversation

@nbut-xzy
Copy link
Contributor

功能改进 / Feature Enhancements

  1. 新增核心接口与实现 / Added Core Interface and Implementations

    • 添加 IPropertyHolder 接口,统一属性访问逻辑
      Added IPropertyHolder interface to unify property access logic
    • 修改 PropertyHolder 类继承自 IPropertyHolder
      Modified PropertyHolder to inherit from IPropertyHolder
    • 新增 PropertyChainHolder 类实现嵌套属性链支持
      Added PropertyChainHolder class to support nested property chains
  2. 嵌套属性映射支持 / Nested Property Mapping Support

    • 修改 EntityDeserializer.ResolveProperty 方法,支持解析如 NestedProp1.NestedProp2 的连续属性路径
      Modified EntityDeserializer.ResolveProperty to resolve chained property paths (e.g., NestedProp1.NestedProp2)
    • 修改 EntityDeserializer.CreateDeserialize 方法,自动初始化空嵌套对象
      Modified EntityDeserializer.CreateDeserialize to auto-initialize null nested objects
    • 支持如下 ResultMap 配置 / Supports ResultMap configuration like:
      <ResultMaps>
        <ResultMap Id="NestedPropertyResultMap">
          <Result Column="Id" Property="Id"/>
          <Result Column="String" Property="NestedProp1.NestedProp2.NestedProp3"/>
        </ResultMap>
      </ResultMaps>
  3. 测试覆盖 / Testing

    • 新增嵌套属性映射单元测试
      Added unit tests for nested property mapping
    • 验证多层级对象初始化与数据完整性
      Validated multi-level object initialization and data integrity

影响范围 / Impact

  • 文件修改 / Modified Files:
    IPropertyHolder.cs, PropertyHolder.cs, PropertyChainHolder.cs, EntityDeserializer.cs
  • 测试新增 / Added Tests:
    EntityDeserializerTest.cs, AllPrimitive.xml, NestedEntity.cs

示例场景 / Example Usage

// 查询并映射嵌套属性 / Query with nested property mapping
var list = SqlMapper.Query<NestedEntity>(new RequestContext
{
    Scope = nameof(AllPrimitive),
    SqlId = "QueryNestedPropertyResult", // SQL statement ID (SQL语句ID)
    Request = new { Taken = 10000 }      // Query parameters (查询参数)
});
<ResultMaps>
 <ResultMap Id="NestedPropertyResultMap">
   <Result Column="Id" Property="Id"/>
   <Result Column="String" Property="NestedProp1.NestedProp2.NestedProp3"/>
 </ResultMap>
</ResultMaps>
public class NestedEntity
{
    public virtual long Id { get; set; }
    public virtual NestedProperty1 NestedProp1 { get; set; }
}
public class NestedProperty1
{
    public virtual NestedProperty2 NestedProp2 { get; set; }
}
public class NestedProperty2
{
    public virtual string NestedProp3 { get; set; }
}

Copy link
Contributor Author

@nbut-xzy nbut-xzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码文件的字符编码从GBK修正为UTF-8;

Copy link
Contributor Author

@nbut-xzy nbut-xzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review changes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释乱码。同时,建议去掉里面的中英文混合注释,还有类似这样的示例注释(例如 User.Address.City)

/// Gets the final property in the chain (��ȡ�����������һ������)
/// Note: Setter is explicitly disabled for immutability (Setter ����ʽ�����Ա�֤���ɱ���)
/// </summary>
public PropertyInfo Property { get => property; set => throw new NotSupportedException(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property为何不直接定义为只读。PropertyInfo Property { get; }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释太多了(中英文混合)

{
internal interface IPropertyHolder
{
PropertyInfo Property { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议 PropertyInfo Property { get; }

@xiangxiren xiangxiren merged commit 8feb4c1 into dotnetcore:master Dec 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants