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

Commit 23cbc3d

Browse files
committed
Add support for using string params larger than default string length
1 parent f37f94f commit 23cbc3d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using NUnit.Framework;
2+
using ServiceStack.DataAnnotations;
3+
4+
namespace ServiceStack.OrmLite.SqlServerTests.Issues
5+
{
6+
class StringLengthParamTest
7+
{
8+
[AutoIncrement]
9+
public int Id { get; set; }
10+
11+
//[CustomField("VARCHAR(MAX)")]
12+
[StringLength(StringLengthAttribute.MaxText)]
13+
public string Name { get; set; }
14+
}
15+
16+
public class StringLengthParamTests
17+
: OrmLiteTestBase
18+
{
19+
[Test]
20+
public void Can_select_param_greater_than_default_length()
21+
{
22+
var hold = OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode;
23+
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = false;
24+
25+
using (var db = OpenDbConnection())
26+
{
27+
db.DropAndCreateTable<StringLengthParamTest>();
28+
29+
var name = "a" + new string('b', 8000) + "c";
30+
31+
db.Insert(new StringLengthParamTest
32+
{
33+
Name = name
34+
});
35+
36+
var people = db.Select<StringLengthParamTest>(p => p.Name == name);
37+
38+
Assert.That(people.Count, Is.EqualTo(1));
39+
}
40+
41+
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = hold;
42+
}
43+
}
44+
}

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,12 @@ public IDbDataParameter CreateParam(string name,
23372337
p.SourceVersion = sourceVersion;
23382338

23392339
if (p.DbType == DbType.String)
2340+
{
23402341
p.Size = DialectProvider.GetStringConverter().StringLength;
2342+
string strValue = value as string;
2343+
if (strValue != null && strValue.Length > p.Size)
2344+
p.Size = strValue.Length;
2345+
}
23412346

23422347
if (value != null)
23432348
{

0 commit comments

Comments
 (0)