FreeSql (twenty-two) Dto mapping query

For those who prefer to use dto friends, often entity with the same name dto attribute, attribute data not fully consistent.

Some people will check back all the field data, and then use AutoMapper map.

Our function is to map, and then query only good field mapping, saving io performance.

Select<Tag>().Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
Select<Tag>().Limit(10).ToList(a => new TestDto());
Select<Tag>().Limit(10).ToList(a => new TestDto { });
Select<Tag>().Limit(10).ToList(a => new TestDto() { });
Select<Tag>().Limit(10).ToList<TestDto>();

This mapping supports single table / multi table.

Find a rule, find the attribute name, will cycle internal object _tables (will increase after the join query) to the main table priority check until found in the same field.

Such as:

A, B, C are id, Dto {id, a1, a2, b1, b2}, A.id mapped. You can also specify id = C.id map.

Friendly reminder: dto be directly mapped a navigation property

Guess you like

Origin www.cnblogs.com/FreeSql/p/11531381.html
dto