Skip to content

增加支持在ResultMap中使用连续属性访问对结果集对象中的嵌套属性赋值; #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nbut-xzy
Copy link

功能改进 / 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; }
}

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.

1 participant