public virtual void NullableInt_literal_generated_correctly() { var typeMapping = new IntTypeMapping("int?", DbType.Int32); Test_GenerateSqlLiteral_helper(typeMapping, default(int?), "NULL"); Test_GenerateSqlLiteral_helper(typeMapping, (int?)123, "123"); }
public virtual void Int_literal_generated_correctly() { var typeMapping = new IntTypeMapping("int", DbType.Int32); Test_GenerateSqlLiteral_helper(typeMapping, int.MinValue, "-2147483648"); Test_GenerateSqlLiteral_helper(typeMapping, int.MaxValue, "2147483647"); }
public virtual void GenerateSqlLiteral_for_Int_works_for_range_limits() { var typeMapping = new IntTypeMapping("int", DbType.Int32); var literal = typeMapping.GenerateSqlLiteral(int.MinValue); Assert.Equal("-2147483648", literal); literal = typeMapping.GenerateSqlLiteral(int.MaxValue); Assert.Equal("2147483647", literal); }
public void Can_create_simple_nullable_parameter_with_DbType() { var parameter = new IntTypeMapping("int", DbType.Int32) .CreateParameter(CreateTestCommand(), "Name", 17, nullable: true); Assert.Equal(ParameterDirection.Input, parameter.Direction); Assert.Equal("Name", parameter.ParameterName); Assert.Equal(17, parameter.Value); Assert.Equal(DbType.Int32, parameter.DbType); Assert.True(parameter.IsNullable); }
public void Can_create_simple_parameter() { var parameter = new IntTypeMapping("int") .CreateParameter(CreateTestCommand(), "Name", 17, nullable: false); Assert.Equal(ParameterDirection.Input, parameter.Direction); Assert.Equal("Name", parameter.ParameterName); Assert.Equal(17, parameter.Value); Assert.Equal(DefaultParameterType, parameter.DbType); Assert.False(parameter.IsNullable); }
void AddCustomizedMappings() { // Mappings where we need literal string generation _baseClrMappings[typeof(string)] = _storeTypeMappings["text"] = new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text); _storeTypeMappings["varchar"] = new NpgsqlStringTypeMapping("varchar", NpgsqlDbType.Varchar); _storeTypeMappings["char"] = new NpgsqlStringTypeMapping("char", NpgsqlDbType.Char); _storeTypeMappings["citext"] = new NpgsqlStringTypeMapping("citext", NpgsqlDbType.Citext); _storeTypeMappings["json"] = new NpgsqlStringTypeMapping("json", NpgsqlDbType.Json); _storeTypeMappings["jsonb"] = new NpgsqlStringTypeMapping("jsonb", NpgsqlDbType.Jsonb); _baseClrMappings[typeof(char)] = new CharTypeMapping("text", DbType.String); _baseClrMappings[typeof(DateTime)] = _storeTypeMappings["timestamp"] = new DateTimeTypeMapping("timestamp", DbType.DateTime); _baseClrMappings[typeof(DateTimeOffset)] = _storeTypeMappings["timestamptz"] = new NpgsqlDateTimeOffsetTypeMapping("timestamptz", DbType.DateTimeOffset); _baseClrMappings[typeof(TimeSpan)] = _storeTypeMappings["interval"] = new NpgsqlTimeSpanTypeMapping(); _baseClrMappings[typeof(bool)] = _storeTypeMappings["bool"] = new NpgsqlBoolTypeMapping(); _baseClrMappings[typeof(decimal)] = new DecimalTypeMapping("numeric", DbType.Decimal); // Note that "decimal" in PostgreSQL is just an alias for numeric, PostgreSQL itself always reports numeric for column types. _baseClrMappings[typeof(Guid)] = _storeTypeMappings["uuid"] = new GuidTypeMapping("uuid", DbType.Guid); _baseClrMappings[typeof(byte[])] = _storeTypeMappings["bytea"] = new NpgsqlByteArrayTypeMapping(); // The following isn't necessary for int itself - a simple ToString() (the default) produces the right // literal representation. However, with an explicit int mapping the standard mapping would be returned // for enums, and there a simple ToString produces the enum *name*. // Example for test for enum literal: InheritanceNpgsqlTest.Can_query_just_roses _baseClrMappings[typeof(short)] = _storeTypeMappings["int2"] = new ShortTypeMapping("int2", DbType.Int16); _baseClrMappings[typeof(int)] = _storeTypeMappings["int4"] = new IntTypeMapping("int4", DbType.Int32); _baseClrMappings[typeof(long)] = _storeTypeMappings["int8"] = new LongTypeMapping("int8", DbType.Int64); // uint is special: there are three internal system uint types: oid, xid, cid. None are supposed to // be truly user-facing, so we don't want to automatically map uint properties to any of them. // However, if the user explicitly sets the properties store type to oid/xid/cid, we want to allow // that (especially since the xmin system column is important for optimistic concurrency). // EFCore doesn't allow a situation where a CLR type has no default store type, so we arbitrarily // choose oid. _baseClrMappings[typeof(uint)] = new NpgsqlBaseTypeMapping("oid", typeof(uint), NpgsqlDbType.Oid); }
public virtual void GenerateSqlLiteral_returns_NullableInt_literal_when_not_null() { var literal = new IntTypeMapping("int?", DbType.Int32).GenerateSqlLiteral((int?)123); Assert.Equal("123", literal); }