Skip to content
Discussion options

You must be logged in to vote

新建一个 dto 类型

.ToList<Dto>()

映射规则如下:

fsql.Select<Song>().ToList<Dto>();
//情况1:Dto 与 Song 属性名相同的字段被查询,返回 List<Dto>

fsql.Select<Song>().ToList(a => new Dto { xxx = a.ext }) 
//情况2:Dto 与 Song 属性名相同的字段被查询,纠正映射 ext,返回 List<Dto>

fsql.Select<Song>().ToList(a => new Song { id = a.id }) 
//情况3:Lambda 与 Song 类型一样,只查询指定字段 id,返回 List<Song>

fsql.Select<Song>().ToList(a => new { id = a.id }) 
//情况4:Lambda 匿名类型,只查询指定字段 id,返回 List<匿名对象>

请仔细处理区别,请仔细处理区别,请仔细处理区别

这种映射支持单表/多表,在查询数据之前映射(不是先查询所有字段再到内存映射)

查找规则,查找属性名,会循环内部对象 _tables(join 查询后会增长),以 主表优先查,直到查到相同的字段。

如:

A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指定 id = C.id 映射。

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ghost
Comment options

@2881099
Comment options

@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant