Beispiel #1
0
        public DuplicatedField(EnumStorage enumStorage, MemberInfo[] memberPath) : base(memberPath)
        {
            _enumStorage = enumStorage;
            _dbType      = TypeMappings.ToDbType(MemberType);


            ColumnName = MemberName.ToTableAlias();

            if (MemberType.GetTypeInfo().IsEnum)
            {
                _parseObject = expression =>
                {
                    var raw = expression.Value();
                    return(Enum.GetName(MemberType, raw));
                };

                _dbType = NpgsqlDbType.Varchar;
                PgType  = "varchar";
            }
            else if (MemberType.IsDateTime())
            {
                PgType  = "timestamp with time zone";
                _dbType = NpgsqlDbType.TimestampTZ;
            }
        }
Beispiel #2
0
        public DuplicatedField(EnumStorage enumStorage, MemberInfo[] memberPath) : base(enumStorage, memberPath)
        {
            ColumnName = MemberName.ToTableAlias();

            if (MemberType.IsEnum)
            {
                if (enumStorage == EnumStorage.AsString)
                {
                    DbType = NpgsqlDbType.Varchar;
                    PgType = "varchar";

                    _parseObject = expression =>
                    {
                        var raw = expression.Value();
                        return(Enum.GetName(MemberType, raw));
                    };
                }
                else
                {
                    DbType = NpgsqlDbType.Integer;
                    PgType = "integer";
                }
            }
            else if (MemberType.IsDateTime())
            {
                PgType = "timestamp without time zone";
                DbType = NpgsqlDbType.Timestamp;
            }
            else if (MemberType.IsDateTime())
            {
                PgType = "timestamp without time zone";
                DbType = NpgsqlDbType.Timestamp;
            }
            else if (MemberType == typeof(DateTimeOffset) || MemberType == typeof(DateTimeOffset?))
            {
                PgType = "timestamp with time zone";
                DbType = NpgsqlDbType.TimestampTz;
            }
            else
            {
                DbType = TypeMappings.ToDbType(MemberType);
            }
        }
Beispiel #3
0
        public DuplicatedField(StoreOptions storeOptions, MemberInfo[] memberPath, bool useTimestampWithoutTimeZoneForDateTime = true, bool notNull = false)
            : base(storeOptions.DuplicatedFieldEnumStorage, memberPath, notNull)
        {
            ColumnName    = MemberName.ToTableAlias();
            _storeOptions = storeOptions;
            this.useTimestampWithoutTimeZoneForDateTime = useTimestampWithoutTimeZoneForDateTime;

            if (MemberType.IsEnum)
            {
                if (storeOptions.DuplicatedFieldEnumStorage == EnumStorage.AsString)
                {
                    DbType = NpgsqlDbType.Varchar;
                    PgType = "varchar";

                    _parseObject = expression =>
                    {
                        var raw = expression.Value();
                        return(Enum.GetName(MemberType, raw));
                    };
                }
                else
                {
                    DbType = NpgsqlDbType.Integer;
                    PgType = "integer";
                }
            }
            else if (MemberType.IsDateTime())
            {
                PgType = this.useTimestampWithoutTimeZoneForDateTime ? "timestamp without time zone" : "timestamp with time zone";
                DbType = this.useTimestampWithoutTimeZoneForDateTime ? NpgsqlDbType.Timestamp : NpgsqlDbType.TimestampTz;
            }
            else if (MemberType == typeof(DateTimeOffset) || MemberType == typeof(DateTimeOffset?))
            {
                PgType = "timestamp with time zone";
                DbType = NpgsqlDbType.TimestampTz;
            }
            else
            {
                DbType = TypeMappings.ToDbType(MemberType);
            }
        }