working with SqlDataReader and AutoMapper.Data

532 views
Skip to first unread message

gilad...@gmail.com

unread,
Feb 1, 2016, 4:37:15 AM2/1/16
to AutoMapper-users
hi,
i'm trying to find an updated sample for mapping an SqlDataReader object into custom one.
 Dim connectionString As String = ConfigurationUtil.ConnectionStrings("xxxx").ConnectionString
        Dim dr As SqlDataReader
        Dim a As AAAA
        Try
            Using cn As New SqlConnection(connectionString)
                Using cm As New SqlCommand
                    cm.Connection = cn
                    cn.Open()
                    cm.CommandType = CommandType.StoredProcedure
                    cm.CommandText = "qf.AAAAGet"
                    cm.Parameters.Add(New SqlParameter("@AAAAId", aaaaId))
                    Dim prmRV As New SqlParameter("@ReturnValue", SqlDbType.Int)
                    prmRV.Direction = ParameterDirection.ReturnValue
                    cm.Parameters.Add(prmRV)

                    dr = cm.ExecuteReader(CommandBehavior.SingleRow)


I would like to map dr into say ACustomObject  (which contains all the fields with the exact names returned in the dr)


1. How do i configure such a mapper ? 
2. How do i call map ?

my thoughts are :
1. In Global.asax call a static method to do the init/config
2. After i'm executing the query do the mapping.

Thanks 

Mario De Schaepmeester

unread,
Feb 1, 2016, 10:41:47 AM2/1/16
to AutoMapper-users
Hello,

I would say that AutoMapper is not the library to use here.

The problem you are trying to solve is widely known as ORM. There are quite a few solutions out there.
If your needs are light-weight, I'd suggest you check out "Dapper". Otherwise you should probably go with Entity Framework or NHibernate.

Gilad Sagiv

unread,
Feb 1, 2016, 10:44:05 AM2/1/16
to automapp...@googlegroups.com
tnx 
I'll check the names you mentioned 

--
You received this message because you are subscribed to a topic in the Google Groups "AutoMapper-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/automapper-users/jznit1na75U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages