Пример #1
0
        private static Func <IDataReader, object> GetDynamicDeserializer(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing)
        {
            var fieldCount = reader.FieldCount;

            if (length == -1)
            {
                length = fieldCount - startBound;
            }

            if (fieldCount <= startBound)
            {
                throw new ArgumentException("fieldCount <= startBound", "splitOn");
            }
            return
                (r =>
            {
                IDictionary <string, object> row = new Dictionary <string, object>(length);
                for (var i = startBound; i < startBound + length; i++)
                {
                    var tmp = r.GetValue(i);
                    tmp = tmp == DBNull.Value ? null : tmp;
                    row[r.GetName(i)] = tmp;
                    if (returnNullIfFirstMissing && i == startBound && tmp == null)
                    {
                        return null;
                    }
                }
                return FastExpando.Attach(row);
            });
        }
Пример #2
0
        private static Func <IDataReader, T> GetDynamicDeserializer <T>(IDataRecord reader, int startBound = 0, int length = -1, bool returnNullIfFirstMissing = false)
        {
            if (length == -1)
            {
                length = reader.FieldCount - startBound;
            }

            return
                (r =>
            {
                IDictionary <string, object> row = new Dictionary <string, object>(length);
                for (var i = startBound; i < startBound + length; i++)
                {
                    var tmp = r.GetValue(i);
                    tmp = tmp == DBNull.Value ? null : tmp;
                    row[r.GetName(i)] = tmp;
                    if (returnNullIfFirstMissing && i == startBound && tmp == null)
                    {
                        return default(T);
                    }
                }
                //we know this is an object so it will not box
                return (T)(object)FastExpando.Attach(row);
            });
        }
Пример #3
0
        public static Func <IDataReader, object> GetDynamicDeserializer(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing)
        {
            var fieldCount = reader.FieldCount;

            if (length == -1)
            {
                length = fieldCount - startBound;
            }

            if (fieldCount <= startBound)
            {
                throw new ArgumentException("When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", "splitOn");
            }

            return
                (r =>
            {
                IDictionary <string, object> row = new Dictionary <string, object>(length);
                for (var i = startBound; i < startBound + length; i++)
                {
                    var tmp = r.GetValue(i);
                    tmp = tmp == DBNull.Value ? null : tmp;
                    row[r.GetName(i)] = tmp;
                    if (returnNullIfFirstMissing && i == startBound && tmp == null)
                    {
                        return null;
                    }
                }
                //we know this is an object so it will not box
                return FastExpando.Attach(row);
            });
        }