Skip to content

Improve handling of SqlCeParameter.SqlDbType #2249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/NHibernate/Driver/SqlServerCeDriver.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Reflection;
using NHibernate.SqlTypes;
using NHibernate.Util;

namespace NHibernate.Driver
{
Expand All @@ -12,6 +11,11 @@ namespace NHibernate.Driver
/// </summary>
public class SqlServerCeDriver : ReflectionBasedDriver
{
private static readonly Action<object, SqlDbType> SetSqlDbType =
DelegateHelper.BuildPropertySetter<SqlDbType>(
ReflectHelper.TypeFromAssembly("System.Data.SqlServerCe.SqlCeParameter", "System.Data.SqlServerCe", true),
"SqlDbType");

/// <summary>
/// Initializes a new instance of the <see cref="SqlServerCeDriver"/> class.
/// </summary>
Expand All @@ -23,19 +27,6 @@ public SqlServerCeDriver()
{
}

private PropertyInfo dbParamSqlDbTypeProperty;

public override void Configure(IDictionary<string, string> settings)
{
base.Configure(settings);

using (var cmd = CreateCommand())
{
var dbParam = cmd.CreateParameter();
dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");
}
}

/// <summary>
/// MsSql requires the use of a Named Prefix in the SQL statement.
/// </summary>
Expand Down Expand Up @@ -109,11 +100,11 @@ private void AdjustDbParamTypeForLargeObjects(DbParameter dbParam, SqlType sqlTy
{
if (sqlType is BinaryBlobSqlType)
{
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null);
SetSqlDbType(dbParam, SqlDbType.Image);
}
else if (sqlType is StringClobSqlType)
{
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.NText, null);
SetSqlDbType(dbParam, SqlDbType.NText);
}
}

Expand Down