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

Commit 9f417e2

Browse files
committed
Fix using JOIN Alias with Schema
1 parent 8263cdb commit 9f417e2

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ protected virtual object VisitSqlMethodCall(MethodCallExpression m)
20692069
statement = DialectProvider.GetQuotedTableName(argDef) + ".*";
20702070
break;
20712071
case "JoinAlias":
2072-
statement = args[0] + "." + quotedColName.ToString().RightPart('.');
2072+
statement = args[0] + "." + quotedColName.ToString().LastRightPart('.');
20732073
break;
20742074
default:
20752075
throw new NotSupportedException();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
using ServiceStack.DataAnnotations;
3+
using ServiceStack.Text;
4+
5+
namespace ServiceStack.OrmLite.Tests.Issues
6+
{
7+
[Schema("Schema")]
8+
public class ModelWithSchema
9+
{
10+
[AutoIncrement]
11+
public int Id { get; set; }
12+
13+
public string Name { get; set; }
14+
15+
public int Value { get; set; }
16+
}
17+
18+
[TestFixture]
19+
public class JoinAliasWithSchemaIssue : OrmLiteTestBase
20+
{
21+
[Test]
22+
public void Can_perform_join_alias_on_ModelWithSchema()
23+
{
24+
using (var db = OpenDbConnection())
25+
{
26+
db.DropAndCreateTable<ModelWithSchema>();
27+
28+
db.Insert(new ModelWithSchema { Name = "One", Value = 1 });
29+
db.Insert(new ModelWithSchema { Name = "Uno", Value = 1 });
30+
31+
var q = db.From<ModelWithSchema>()
32+
.Join<ModelWithSchema>((a, b) => a.Value == b.Value, db.JoinAlias("b"))
33+
.Select(x => new
34+
{
35+
AName = x.Name,
36+
BName = Sql.JoinAlias(x.Name, "b")
37+
});
38+
39+
var results = db.Select<object>(q);
40+
db.GetLastSql().Print();
41+
Assert.That(results.Count, Is.EqualTo(2 * 2));
42+
}
43+
}
44+
}
45+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<Compile Include="Async\SqlServerProviderTestsAsync.cs" />
142142
<Compile Include="Async\UpdateAsyncTests.cs" />
143143
<Compile Include="Expression\SqlExpressionJoinTests.cs" />
144+
<Compile Include="Issues\JoinAliasWithSchemaIssue.cs" />
144145
<Compile Include="UseCase\CustomerOrdersUseCaseAsync.cs" />
145146
<Compile Include="AutoQueryTests.cs" />
146147
<Compile Include="CaptureSqlCommandFilterTests.cs" />

0 commit comments

Comments
 (0)