示例#1
0
        // set value on CLR object from db value returned by pg reader
        public void SetValue(object obj, object value)
        {
            object resolvedValue = DbValueToObjectMapper.Map(value, _property.PropertyType, DataType);

            if (NotNull && resolvedValue == null)
            {
                throw new InvalidOperationException($"Column '{Name}' requires a value but was tried to set as null.");
            }

            _property.SetValue(obj, resolvedValue);
        }
示例#2
0
        public static Func <NpgsqlDataReader, List <TResult> > Create <TResult>(Type propertyType, PostgresDataType dataType)
        {
            return(reader =>
            {
                var result = new List <object>();

                while (reader.Read())
                {
                    Debug.Assert(reader.FieldCount == 1, "Union queries only support selecting a single column.");

                    object value = reader.GetValue(0);
                    object resolvedValue = DbValueToObjectMapper.Map(value, propertyType, dataType);

                    result.Add(resolvedValue);
                }

                return result.Cast <TResult>().ToList();
            });
        }