Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit fd8cc1d

Browse files
committed
Change SqlServerStringConverter to use VarChar when !UseUnicode
1 parent b76a470 commit fd8cc1d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/ServiceStack.OrmLite.SqlServer/Converters/SqlServerStringConverters.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using System;
2+
using System.Data;
3+
using System.Data.SqlClient;
24
using ServiceStack.DataAnnotations;
35
using ServiceStack.OrmLite.Converters;
46

57
namespace ServiceStack.OrmLite.SqlServer.Converters
68
{
79
public class SqlServerStringConverter : StringConverter
810
{
9-
public override string MaxColumnDefinition
10-
{
11-
get { return UseUnicode ? "NVARCHAR(MAX)" : "VARCHAR(MAX)"; }
12-
}
11+
public override string MaxColumnDefinition => UseUnicode ? "NVARCHAR(MAX)" : "VARCHAR(MAX)";
1312

1413
public override string GetColumnDefinition(int? stringLength)
1514
{
@@ -24,5 +23,18 @@ public override string GetColumnDefinition(int? stringLength)
2423
? "NVARCHAR({0})".Fmt(safeLength)
2524
: "VARCHAR({0})".Fmt(safeLength);
2625
}
26+
27+
public override void InitDbParam(IDbDataParameter p, Type fieldType)
28+
{
29+
base.InitDbParam(p, fieldType);
30+
31+
var sqlParam = p as SqlParameter;
32+
if (sqlParam == null) return;
33+
34+
if (!UseUnicode)
35+
{
36+
sqlParam.SqlDbType = SqlDbType.VarChar;
37+
}
38+
}
2739
}
2840
}

0 commit comments

Comments
 (0)