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

Commit 636d6e5

Browse files
committed
Add OrmLiteConfig.DisableColumnGuessFallback to disable TryGuessColumnIndex
1 parent 7484ca7 commit 636d6e5

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

src/ServiceStack.OrmLite/OrmLiteConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public static IDbConnection ToDbConnection(this string dbConnectionStringOrFileP
103103
return dbConn;
104104
}
105105

106+
public static bool DisableColumnGuessFallback { get; set; }
106107
public static bool StripUpperInLike { get; set; }
107108

108109
private static IOrmLiteExecFilter execFilter;

src/ServiceStack.OrmLite/OrmLiteWriteExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ public static T PopulateWithSqlReader<T>(this T objWithProperties, IDataReader d
314314

315315
private static int TryGuessColumnIndex(string fieldName, IDataReader dataReader)
316316
{
317+
if (OrmLiteConfig.DisableColumnGuessFallback)
318+
return NotFound;
319+
317320
var fieldCount = dataReader.FieldCount;
318321
for (var i = 0; i < fieldCount; i++)
319322
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
4+
using ServiceStack.Model;
5+
using ServiceStack.Text;
6+
7+
namespace ServiceStack.OrmLite.Tests.Issues
8+
{
9+
public class DbPoco : IHasId<string>
10+
{
11+
[Alias("Id_primary")]
12+
public string Id { get; set; }
13+
14+
public string Other_Id { get; set; }
15+
}
16+
17+
public class DTOPoco
18+
{
19+
public string Id { get; set; }
20+
public string Other_Id { get; set; }
21+
}
22+
23+
[TestFixture]
24+
public class SelectIntoTests
25+
: OrmLiteTestBase
26+
{
27+
[Test]
28+
public void Dont_guess_column_in_mismatched_Into_model()
29+
{
30+
OrmLiteConfig.DisableColumnGuessFallback = true;
31+
32+
using (var db = OpenDbConnection())
33+
{
34+
db.DropAndCreateTable<DbPoco>();
35+
36+
db.Insert(new DbPoco { Id = "1", Other_Id = "OTHER" });
37+
38+
var row = db.Select<DTOPoco>(db.From<DbPoco>()).First();
39+
40+
row.PrintDump();
41+
42+
Assert.That(row.Id, Is.Null);
43+
Assert.That(row.Other_Id, Is.EqualTo("OTHER"));
44+
}
45+
46+
OrmLiteConfig.DisableColumnGuessFallback = false;
47+
}
48+
}
49+
}

tests/ServiceStack.OrmLite.Tests/PerfTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Diagnostics;
22
using NUnit.Framework;
3-
using ServiceStack.Common.Tests.Models;
43
using ServiceStack.DataAnnotations;
54
using ServiceStack.Text;
65

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
<Compile Include="Expression\SelectExpressionTests.cs" />
126126
<Compile Include="Issues\MismatchSchemaTests.cs" />
127127
<Compile Include="Issues\MultithreadingIssueTests.cs" />
128+
<Compile Include="Issues\SelectIntoTests.cs" />
128129
<Compile Include="LicenseUsageTests.cs" />
129130
<Compile Include="LoadReferencesJoinTests.cs" />
130131
<Compile Include="LoadReferencesTests.cs" />

0 commit comments

Comments
 (0)