With AutoMapper, there is no need to manually assign a one-to-a-idatareader to an entity field. This blog post is a record of the actual case.
The entity type is defined as follows:
Public class uploadimage{ publicintgetset;} Public string Get Set ; }}
The SRC attribute corresponds to the field name ImageUrl in the database.
Mapping requirements: from IDataReader to Ienumerable<uploadimage>, the code is as follows:
using(varconn =NewSqlConnection (Connectionstrings.default)) { using(varCommand =Conn. CreateCommand ()) {Command.commandtype=System.Data.CommandType.Text; Command.commandtext="..."; awaitConn. OpenAsync (); using(IDataReader reader =awaitcommand. Executereaderasync ()) {returnAutomapper.mapper.map<idatareader, ienumerable<uploadimage>>(reader); } }}
This mapping can be implemented by configuring AutoMapper with the Imappingexpression.formember () method, with the following code:
This is a very representative
Automapper.mapper.createmap<idatareader, uploadimage>() = dest. SRC, Options and options. Mapfrom ( = = src. GetString (src. GetOrdinal ("ImageUrl"
AutoMapper specifying column names for mapping