How can I map the results of a sql query onto objects?

后端 未结 7 1667
灰色年华
灰色年华 2021-02-01 20:37

Currently, I am using something like this:

    try
    {
      dr = SQL.Execute(sql);

      if(dr != null) {
         while(dr.Read()) {
           CustomObject         


        
7条回答
  •  一生所求
    2021-02-01 21:02

    When searching for this answer I found that you can use Dapper library: https://dapper-tutorial.net/knowledge-base/44980945/querying-into-a-complex-object-with-dapper

    You can use something like this:

            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                IList result = connection.Query(sql, commandType: CommandType.Text).ToList();
            }
    

提交回复
热议问题