Use our own Byte type mapping for generating the correct string literal

pull/137/head
Christopher Jolly 3 years ago
parent bc5b51fa4a
commit 78f3dbae15

@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Data;
using System.Globalization;
using System.Text;
using Microsoft.EntityFrameworkCore.Storage;
namespace EntityFrameworkCore.Jet.Storage.Internal;
/// <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 JetByteTypeMapping : ByteTypeMapping
{
/// <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 JetByteTypeMapping(
string storeType,
DbType? dbType = System.Data.DbType.Byte)
: base(storeType, dbType)
{
}
/// <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 JetByteTypeMapping(RelationalTypeMappingParameters parameters)
: base(parameters)
{
}
/// <summary>
/// Creates a copy of this mapping.
/// </summary>
/// <param name="parameters">The parameters for this mapping.</param>
/// <returns>The newly created mapping.</returns>
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
=> new JetByteTypeMapping(parameters);
/// <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 string GenerateNonNullSqlLiteral(object value)
{
var builder = new StringBuilder();
builder.Append("0x");
var bt = Convert.ToByte(value);
builder.Append(bt.ToString("X2", CultureInfo.InvariantCulture));
return builder.ToString();
}
}

@ -32,7 +32,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
// is determined by the value generation type.
private readonly IntTypeMapping _counter = new JetIntTypeMapping("integer");
private readonly ByteTypeMapping _byte = new ByteTypeMapping("byte", DbType.Byte); // unsigned, there is no signed byte in Jet
private readonly JetByteTypeMapping _byte = new JetByteTypeMapping("byte", DbType.Byte); // unsigned, there is no signed byte in Jet
private readonly ShortTypeMapping _smallint = new ShortTypeMapping("smallint", DbType.Int16);
private readonly IntTypeMapping _integer = new JetIntTypeMapping("integer");
private readonly JetLongTypeMapping _bigint = new JetLongTypeMapping("integer");//a long and integer are the same in Jet

Loading…
Cancel
Save