ServiceStack/ServiceStack.OrmLite — pull request #271 by fvoncina (2013-07-04 02:11:15+00:00)
Title: Prevent raising inner exceptions while IDataReader tries to get ordinal for field names.

In some RBMS (MSSQL, PostgreSQL, etc) the method IDataReader.GetOrdinal functions throws an IndexOutRangeException instead or returning -1 for a non existent field.

If in the DTO you have ignored fields the OrmLiteWriterExtensions.PopulateWithSqlReader method will try to find every field, even if it is marked to be ignored (that is to support JoinFeature), but in scenarios like db.Select() where author has ignored fields, the method GetColumnIndex will produce a inner exception per every ignored field multiplied by the number or rows.

I've added an extension method OrmLiteUtilExtensions.GetIndexFieldsCache who returns a dictionary with the names and positions of every field inside an opened IDataReader. That cache of fields and ordinal positions is passed to the function OrmLiteWriterExtensions.PopulateWithSqlReader to avoid trying to get the ordinal directly from the reader.

The performance penalty is almost nothing because the read of IDataReader field names and positions occurs on per dataset query.