提交 a1e00bd1 编写于 作者: S Shay Rojansky

Bring back array scaffolding

Fixes #205
上级 0a1fd459
......@@ -242,8 +242,10 @@ void GetColumns()
// Base (regular), is the default
break;
case 'a':
column[NpgsqlAnnotationNames.PostgresTypeType] = PostgresTypeType.Array;
column[NpgsqlAnnotationNames.ElementDataType] = elemDataType;
// PG array types in pg_type start with underscores (_int for array of int), but the type name
// PG accepts when creating columns is int[], translate.
if (column.StoreType.StartsWith("_"))
column.StoreType = column.StoreType.Substring(1) + "[]";
break;
case 'r':
column[NpgsqlAnnotationNames.PostgresTypeType] = PostgresTypeType.Range;
......
......@@ -34,20 +34,21 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal
{
public sealed class NpgsqlArrayTypeMapping : NpgsqlTypeMapping
{
//readonly NpgsqlDbType? _npgsqlDbType;
public RelationalTypeMapping ElementMapping { get; private set; }
internal NpgsqlArrayTypeMapping(Type arrayClrType, RelationalTypeMapping elementMapping)
: base('_' + elementMapping.StoreType, arrayClrType)
: base(elementMapping.StoreType + "[]", arrayClrType)
{
ElementMapping = elementMapping;
//if (elementMapping.NpgsqlDbType.HasValue)
// _npgsqlDbType = elementMapping.NpgsqlDbType.Value | NpgsqlTypes.NpgsqlDbType.Array;
if (elementMapping is NpgsqlTypeMapping m && m.NpgsqlDbType.HasValue)
NpgsqlDbType = m.NpgsqlDbType.Value | NpgsqlTypes.NpgsqlDbType.Array;
}
//public override RelationalTypeMapping CreateCopy(string storeType, int? size)
// => new NpgsqlArrayTypeMapping(storeType, DbType);
public override RelationalTypeMapping Clone(string storeType, int? size)
=> new NpgsqlTypeMapping(storeType, ClrType, NpgsqlDbType);
protected override string GenerateNonNullSqlLiteral(object value)
=> throw new NotSupportedException("Can't generate array literals (yet)");
}
}
......@@ -15,12 +15,9 @@ public class NpgsqlTypeMapping : RelationalTypeMapping
{
public NpgsqlDbType? NpgsqlDbType { get; protected set; }
readonly Type _type;
internal NpgsqlTypeMapping([NotNull] string storeType, [NotNull] Type clrType, NpgsqlDbType? npgsqlDbType = null)
: base(storeType, clrType, unicode: false, size: null, dbType: null)
{
_type = clrType;
NpgsqlDbType = npgsqlDbType;
}
......@@ -31,6 +28,6 @@ protected override void ConfigureParameter([NotNull] DbParameter parameter)
}
public override RelationalTypeMapping Clone(string storeType, int? size)
=> new NpgsqlTypeMapping(storeType, _type, NpgsqlDbType);
=> new NpgsqlTypeMapping(storeType, ClrType, NpgsqlDbType);
}
}
......@@ -73,6 +73,7 @@ public NpgsqlEFTypeMapper([NotNull] RelationalTypeMapperDependencies dependencie
StringMapper = new NpgsqlStringRelationalTypeMapper();
AddCustomizedMappings();
AddArrayStoreMappings();
}
void AddCustomizedMappings()
......@@ -112,6 +113,15 @@ void AddCustomizedMappings()
_baseClrMappings[typeof(uint)] = new NpgsqlBaseTypeMapping("oid", typeof(uint), NpgsqlDbType.Oid);
}
void AddArrayStoreMappings()
{
foreach (var elementMapping in _storeTypeMappings.Values.ToList())
{
var arrayMapping = new NpgsqlArrayTypeMapping(elementMapping.ClrType.MakeArrayType(), elementMapping);
_storeTypeMappings[arrayMapping.StoreType] = arrayMapping;
}
}
protected override string GetColumnType(IProperty property) => property.Npgsql().ColumnType;
protected override IReadOnlyDictionary<Type, RelationalTypeMapping> GetClrTypeMappings()
......
......@@ -10,5 +10,6 @@ namespace E2ETest.Namespace
public int SpecialTypesId { get; set; }
public IPAddress IpAddress { get; set; }
public PhysicalAddress MacAddress { get; set; }
public int[] IntArray { get; set; }
}
}
......@@ -13,5 +13,6 @@ namespace E2ETest.Namespace
public int SpecialTypesId { get; set; }
public IPAddress IpAddress { get; set; }
public PhysicalAddress MacAddress { get; set; }
public int[] IntArray { get; set; }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册