{"action":"created","issue":{"url":"https://api.github.com/repos/StackExchange/Dapper/issues/1015","repository_url":"https://api.github.com/repos/StackExchange/Dapper","labels_url":"https://api.github.com/repos/StackExchange/Dapper/issues/1015/labels{/name}","comments_url":"https://api.github.com/repos/StackExchange/Dapper/issues/1015/comments","events_url":"https://api.github.com/repos/StackExchange/Dapper/issues/1015/events","html_url":"https://github.com/StackExchange/Dapper/issues/1015","id":317801747,"number":1015,"title":"Multi mapper assumes that `splitOn` column is never 0-index in IDbDataReader","user":{"login":"bawkee","id":38323343,"avatar_url":"https://avatars0.githubusercontent.com/u/38323343?v=4","gravatar_id":"","url":"https://api.github.com/users/bawkee","html_url":"https://github.com/bawkee","followers_url":"https://api.github.com/users/bawkee/followers","following_url":"https://api.github.com/users/bawkee/following{/other_user}","gists_url":"https://api.github.com/users/bawkee/gists{/gist_id}","starred_url":"https://api.github.com/users/bawkee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bawkee/subscriptions","organizations_url":"https://api.github.com/users/bawkee/orgs","repos_url":"https://api.github.com/users/bawkee/repos","events_url":"https://api.github.com/users/bawkee/events{/privacy}","received_events_url":"https://api.github.com/users/bawkee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-25T21:32:49Z","updated_at":"2018-05-01T20:43:35Z","closed_at":"2018-05-01T20:43:35Z","author_association":"NONE","body":"Hi,\r\n\r\nI noticed in Dapper that if the column specified in `splitOn` argument in its `Query` method is first in the SELECT statement, Dapper will throw the `MultiMapException` because it can't find it. \r\n\r\nThis is because the `for` loop in below method skips the first column due to `i > 0`:\r\n\r\nFrom [SqlMapper.cs](../blob/master/Dapper/SqlMapper.cs)\r\n```C#\r\nprivate static int GetNextSplit(int startIdx, string splitOn, IDataReader reader)\r\n{\r\n\tif (splitOn == \"*\")\r\n\t{\r\n\t\treturn --startIdx;\r\n\t}\r\n\r\n\tfor (var i = startIdx - 1; i > 0; --i)\r\n\t{\r\n\t\tif (string.Equals(splitOn, reader.GetName(i), StringComparison.OrdinalIgnoreCase))\r\n\t\t{\r\n\t\t\treturn i;\r\n\t\t}\r\n\t}\r\n\r\n\tthrow MultiMapException(reader);\r\n}\r\n```\r\n\r\nNow I haven't ever used dapper in any production so I may be missing something big here but I spent several hours trying to figure out any reason why would this be to no avail. \r\n\r\nFor example, consider the following tutorial I found on http://dapper-tutorial.net/:\r\nhttps://dotnetfiddle.net/DPiy2b\r\n\r\nIt works because it has `SELECT *`, but if you change that SELECT statement to:\r\n```SQL\r\nSELECT A.OrderID, CustomerID, EmployeeID, OrderDate, ShipperID, ProductID, Quantity\r\n```\r\nDapper will throw the aforementioned exception.\r\n\r\nChanging the SQL to:\r\n```SQL\r\nSELECT A.OrderID, A.OrderID, CustomerID, EmployeeID, OrderDate, ShipperID, ProductID, Quantity\r\n```\r\nAvoids the exception, because Dapper will pick up OrderID when mapping since it starts from 1.\r\n\r\nAgain this may very well be *by design*, I can't tell straight away as I've only used dapper for couple of hours since 2015. If it is and I missed something obvious, I apologise for wasting everyone's time! "},"comment":{"url":"https://api.github.com/repos/StackExchange/Dapper/issues/comments/385784153","html_url":"https://github.com/StackExchange/Dapper/issues/1015#issuecomment-385784153","issue_url":"https://api.github.com/repos/StackExchange/Dapper/issues/1015","id":385784153,"user":{"login":"bawkee","id":38323343,"avatar_url":"https://avatars0.githubusercontent.com/u/38323343?v=4","gravatar_id":"","url":"https://api.github.com/users/bawkee","html_url":"https://github.com/bawkee","followers_url":"https://api.github.com/users/bawkee/followers","following_url":"https://api.github.com/users/bawkee/following{/other_user}","gists_url":"https://api.github.com/users/bawkee/gists{/gist_id}","starred_url":"https://api.github.com/users/bawkee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bawkee/subscriptions","organizations_url":"https://api.github.com/users/bawkee/orgs","repos_url":"https://api.github.com/users/bawkee/repos","events_url":"https://api.github.com/users/bawkee/events{/privacy}","received_events_url":"https://api.github.com/users/bawkee/received_events","type":"User","site_admin":false},"created_at":"2018-05-01T20:43:35Z","updated_at":"2018-05-01T20:43:35Z","author_association":"NONE","body":"@MrJerB Thanks, I had a totally incorrect idea on how multimapping mechanism works and my sample DB driver (Access) didn't help at all. After some more investigation I figured it out, [this SO answer helped me a lot](https://stackoverflow.com/questions/7472088/correct-use-of-multimapping-in-dapper)."}}
{"actor":{"display_login":"bawkee"}}