sai kumar

sai kumar

  • NA
  • 14
  • 16k

How to map DataTable to DTO?

Oct 8 2016 6:21 AM
  1. string connString = @"server =.; database =appsword; uid = madhubaabu; pwd = Welcome@123; ";  
  2. string query = "SELECT distinct TOP 5 ISNULL(C.Name, 'Others') AS 'Company',A.Name AS 'Customers', O.Fee AS 'Amount' FROM   ClientCursor.Opportunity AS O INNER JOIN Common.Company AS C ON C.Id = O.ServiceCompanyId INNER JOIN [ClientCursor].[Account] AS A ON A.Id = O.AccountId order by  O.Fee DESC"

  3.             SqlConnection conn = new SqlConnection(connString);  
  4.             conn.Open();  
  5.             SqlCommand cmd = new SqlCommand(query, conn);  
  6.             SqlDataAdapter da=new SqlDataAdapter(cmd);  
  7.             DataSet ds = new DataSet(); //conn is opened by dataadapter  
  8.             da.Fill(ds,"newtbale");  
  9.             return ds; 
I'm new to AutoMapper and have couple of questions regarding datatable to object mapping.I have sqlquery code and sql result like above.I want to do object to object  map with automapper, i.e,transfer datatable to Class object(viewmodel) by using ado.net. can anybody help on this!
 

Answers (2)