未验证 提交 db80fec8 编写于 作者: S Shay Rojansky 提交者: GitHub

Support xid8 (#2619)

Closes #2618
上级 3e4ef719
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class NpgsqlULongTypeMapping : NpgsqlTypeMapping
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public NpgsqlULongTypeMapping(string storeType, NpgsqlDbType npgsqlDbType)
: base(storeType, typeof(ulong), npgsqlDbType) {}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected NpgsqlULongTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType)
: base(parameters, npgsqlDbType) {}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
=> new NpgsqlULongTypeMapping(parameters, NpgsqlDbType);
}
......@@ -129,8 +129,9 @@ static NpgsqlTypeMappingSource()
private readonly NpgsqlPolygonTypeMapping _polygon = new();
private readonly NpgsqlCircleTypeMapping _circle = new();
// uint mappings
// uint/ulong mappings
private readonly NpgsqlUintTypeMapping _xid = new("xid", NpgsqlDbType.Xid);
private readonly NpgsqlULongTypeMapping _xid8 = new("xid8", NpgsqlDbType.Xid8);
private readonly NpgsqlUintTypeMapping _oid = new("oid", NpgsqlDbType.Oid);
private readonly NpgsqlUintTypeMapping _cid = new("cid", NpgsqlDbType.Cid);
private readonly NpgsqlUintTypeMapping _regtype = new("regtype", NpgsqlDbType.Regtype);
......@@ -326,6 +327,7 @@ static NpgsqlTypeMappingSource()
{ "circle", new[] { _circle } },
{ "xid", new[] { _xid } },
{ "xid8", new[] { _xid8 } },
{ "oid", new[] { _oid } },
{ "cid", new[] { _cid } },
{ "regtype", new[] { _regtype } },
......@@ -533,7 +535,7 @@ protected virtual void SetupEnumMappings(ISqlGenerationHelper sqlGenerationHelpe
}
// Map arbitrary user POCOs to JSON
if (storeTypeName == "jsonb" || storeTypeName == "json")
if (storeTypeName is "jsonb" or "json")
{
return new NpgsqlJsonTypeMapping(storeTypeName, clrType);
}
......@@ -614,9 +616,17 @@ protected virtual void SetupEnumMappings(ISqlGenerationHelper sqlGenerationHelpe
return mapping;
}
if (clrType == typeof(uint) && mappingInfo.IsRowVersion == true)
if (mappingInfo.IsRowVersion == true)
{
return _xid;
if (clrType == typeof(uint))
{
return _xid;
}
if (clrType == typeof(ulong))
{
return _xid8;
}
}
}
......
......@@ -35,6 +35,8 @@ public class NpgsqlTypeMappingSourceTest
[InlineData("geometry(pointz, 4326)", typeof(Point), null, false)]
[InlineData("geography(LineStringZM)", typeof(LineString), null, false)]
[InlineData("geometry(POLYGONM)", typeof(Polygon), null, false)]
[InlineData("xid", typeof(uint), null, false)]
[InlineData("xid8", typeof(ulong), null, false)]
public void By_StoreType(string typeName, Type type, int? size, bool fixedLength)
{
var mapping = CreateTypeMappingSource().FindMapping(typeName);
......@@ -138,6 +140,8 @@ public void By_ClrType_and_precision(Type clrType, string expectedStoreType)
[InlineData("dummyrange", typeof(NpgsqlRange<DummyType>))]
[InlineData("geometry", typeof(Geometry))]
[InlineData("geometry(Point, 4326)", typeof(Geometry))]
[InlineData("xid", typeof(uint))]
[InlineData("xid8", typeof(ulong))]
public void By_StoreType_with_ClrType(string storeType, Type clrType)
{
var mapping = CreateTypeMappingSource().FindMapping(clrType, storeType);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册