Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the GridReader.Read method with Type [] types and … #308

Merged
merged 1 commit into from Oct 15, 2015

Conversation

NikolayGlynchak
Copy link
Contributor

… Func<object[], TResult> to map back to more than 7 objects.

…], TResult> to map back to more than 7 objects.
@johandanforth
Copy link
Contributor

Looks ok. Do you have a short sample of how to use?

@NikolayGlynchak
Copy link
Contributor Author

New method has been tested and used in a real project. Here is the sample code:

      public TaskDTO GetTask()
        {
            try
            {
                using (ConnectionManager connectionManager = new ConnectionManager())
                {
                    using (var reader = connectionManager.GetConnection().QueryMultiple("PR_GetTask", commandType: CommandType.StoredProcedure, param: new { taskID }))
                    {
                        // Read first recordset
                        var result = reader.Read<TaskDTO>(
                            types: new[]
                                   {
                                       typeof (TaskDTO),
                                       typeof (EngineDTO),
                                       typeof (ModelDTO),
                                       typeof (BrandDTO),
                                       typeof (VehicleTypeDTO),
                                       typeof (UserDTO),
                                       typeof (EmailAddressDTO),
                                       typeof (CurrencyDTO)
                                   },
                            map: objects =>
                                 {
                                     TaskDTO processingTask = (TaskDTO)objects[0];
                                     processingTask.Engine = (EngineDTO)objects[1];
                                     processingTask.Engine.Model = (ModelDTO)objects[2];
                                     processingTask.Engine.Model.Brand = (BrandDTO)objects[3];
                                     processingTask.Engine.Model.Brand.VehicleType = (VehicleTypeDTO)objects[4];
                                     processingTask.User = (UserDTO)objects[5];
                                     processingTask.User.EmailAddress = (EmailAddressDTO)objects[6];
                                     processingTask.Currency = (CurrencyDTO)objects[7];

                                     return processingTask;
                                 }, splitOn: "EngineID, ModelID, BrandID, VehicleTypeID, UserID, EmailAddressID, CurrencyID").FirstOrDefault();

                        if (result != null)
                        {
                            // Read second recordset
                            result.ActionGroups = reader.Read<ActionGroupDTO>().ToList();

                            // Read third recordset
                            result.IdentificationResults = reader.Read<IdentificationResultDTO>().ToList();
                        }

                        return result;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ProcessError(TasksRepositoryStrings.GetTaskErrorMsg, ex, _log);
            }
        }

@NikolayGlynchak NikolayGlynchak changed the title Added then GridReader.Read method with Type [] types and … Added the GridReader.Read method with Type [] types and … Jun 27, 2015
NickCraver added a commit that referenced this pull request Oct 15, 2015
Added the GridReader.Read method with Type [] types and …
@NickCraver NickCraver merged commit 83b47e3 into DapperLib:master Oct 15, 2015
@NickCraver
Copy link
Member

Finally getting around to pulling this in, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants