System.Data.Common.DbDataReader.GetColumnOrdinal(string)

Here are the examples of the csharp api class System.Data.Common.DbDataReader.GetColumnOrdinal(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Example 7

1. Example

Project: EasyLOB
Source File: DbDataReaderExtensions.cs
public static T ToEntity<T>(this DbDataReader reader)
        {
            T entity = (T)Activator.CreateInstance(typeof(T));

            List<string> properties = LibraryHelper.GetProperties(typeof(T));
            foreach (string property in properties)
            {
                int ordinal = reader.GetColumnOrdinal(property);
                if (ordinal >= 0)
                {
                    object value = reader.GetValue(ordinal);
                    if (!(value is DBNull))
                    {
                        LibraryHelper.SetPropertyValue(entity, property, value);
                    }
                }
            }

            return entity;
        }