Skip to content
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

实体模型更新功能 #15

Open
niltor opened this issue Oct 19, 2024 · 0 comments
Open

实体模型更新功能 #15

niltor opened this issue Oct 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@niltor
Copy link
Contributor

niltor commented Oct 19, 2024

场景

在开发阶段,时常会对实体模型进行修改和调整,如添加/修改/删除字段等。

如果已经生成了Dto,当对实体修改后,还需要手动修改各个Dto,比较麻烦。

解决办法

可以重新生成Dto,覆盖旧的Dto。这适合没有对Dto进行自定义修改的情况下,否则重新生成会将丢失自定义的内容。

为了解决这个问题,希望提供一键更新Dto的功能,它具有以下特点:

当对原始实体进行 新增/删除(变更可视为先删除后新增)操作后,相应的DTO也能同步更新。如将以下实体

class User
{
    public Guid ID { get; set; }
    public required string Username { get; set; }
    public SexType? SexType { get; set; }
    public string? AdditionInfo { get; set; }
}

修改为:

class User{

    public Guid Id { get; set; }
    public required string UserName { get; set; }
    public SexType? SexType { get; set; }
    public string? RealName { get; set; }
}

处理步骤如下:

  1. 读取旧实体内容(每次生成时入库存储),重新生成Dto,然后与现有代码Dto进行对比,找出用户额外添加和删除的属性。
  2. 按照新实体模型,生成新的Dto,然后将用户额外添加和删除的属性与之合并即可。

此种作法可满足常见的普遍的更新需求,更加复杂的情况仍然需求手动调整。

@niltor niltor self-assigned this Oct 19, 2024
@niltor niltor added the enhancement New feature or request label Oct 19, 2024
@niltor niltor added this to the 9.0 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant