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

+更新dto方法 #218

Closed
zhontai opened this issue Feb 27, 2020 · 3 comments
Closed

+更新dto方法 #218

zhontai opened this issue Feb 27, 2020 · 3 comments

Comments

@zhontai
Copy link

zhontai commented Feb 27, 2020

增加直接更新dto所有数据 + 实体审计数据的功能
为解决attach(entity) 会意外更新其它字段或者默认值无变化无法更新该字段的问题
entity = entityRep.getAsync(dto.id)
_mapper.Map(dto)
entityRep.UpdateAsync(entity) 这里更新需要查询再更新有变化的字段
场景:
_entity仓储.updateDto(dto) => update entityTable set dto.所有字段 + 内部获取 new entity(){ }.更新审计字段

@2881099
Copy link
Collaborator

2881099 commented Feb 28, 2020

根据 Dto 更新

fsql.Update<T>()
  .SetDto(new { title = "xxx", clicks = 2 })
  .Where(a => a.Id == 1)
  .ExecuteAffrows();
//UPDATE `tb_topic` SET `Title` = ?p_0, `Clicks` = ?p_1 WHERE (Id = 1)

fsql.Update<T>()
  .SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 })
  .Where(a => a.Id == 1)
  .ExecuteAffrows();

@a6336747
Copy link

大佬,你好,Insert是否也能添加类似匿名,或者Dto方式的录入呢?
fsql.Insert<Sys_LogDto>(log).AsTable(d => "Sys_Log").ExecuteAffrows();
比如现在我要录入Dto数据只能通过这样的形式插入,感激不尽

@2881099
Copy link
Collaborator

2881099 commented Mar 17, 2020

大佬,你好,Insert是否也能添加类似匿名,或者Dto方式的录入呢?
fsql.Insert<Sys_LogDto>(log).AsTable(d => "Sys_Log").ExecuteAffrows();
比如现在我要录入Dto数据只能通过这样的形式插入,感激不尽

不一样,更新才需要指定字段。插入可以考虑把 Dto 对象映射成 Entity 在插入

@2881099 2881099 closed this as completed May 1, 2020
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

No branches or pull requests

3 participants