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

fsql.Select<>().ToList(a => new DTO { }) 自动映射Dto字段至实体真实字段名而不是属性名是否合适 #208

Closed
tky753 opened this issue Feb 12, 2020 · 4 comments

Comments

@tky753
Copy link
Contributor

@tky753 tky753 commented Feb 12, 2020

个人感觉 Dto属性的名称 应该和 实体 的属性名 相同时自动 查询映射比较合理吧。
现在是和 数据表的字段名相同时才自动 查询映射。
总不能把真实字段名 传输到客户端吧,那不就暴露表结构了吗?

FreeSql是不是不推荐直接查询Dto,而是先查询 实体,再通过Automapper等工具来映射?
或者Dto也要加上[Column(Name="")]特性 ?

@tky753

This comment has been minimized.

Copy link
Contributor Author

@tky753 tky753 commented Feb 12, 2020

说错了,好像Dto 加上 [Column(Name="")]特性也没用

@2881099

This comment has been minimized.

Copy link
Owner

@2881099 2881099 commented Feb 12, 2020

dto很多人在用,推荐使用。这个还真是,没人提这个问题,有可能都接受了,或者他们属性名和表字段名相同。

@tky753

This comment has been minimized.

Copy link
Contributor Author

@tky753 tky753 commented Feb 12, 2020

现在的项目大多都属性名和表字段名相同了吧。我这个项目的数据库是10年前开始用的,以前都是直接查询返回DataTable的

@2881099

This comment has been minimized.

Copy link
Owner

@2881099 2881099 commented Feb 12, 2020

if (dtTb.Table.ColumnsByCs.TryGetValue(dtoProp.Name, out trydtocol) == false)
    continue;

目前有两种情况:

ToList(a => new Dto());

ToList(a => new Dto() { });

第一种没问题,是从属性映射查找的

第二种有问题,是从 Columns 字段名查找的

原来没有统一,我修复一下问题2。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.