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

Commit bbaeafc

Browse files
authored
Merge pull request #2 from ServiceStack/master
Merge from upsteam branch 29.07.2016
2 parents 5ecad0d + 221fafb commit bbaeafc

29 files changed

+733
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,11 +1245,11 @@ using (var db = OpenDbConnection())
12451245
}
12461246
```
12471247

1248-
Results filters makes it trivial to implement the `CaptureSqlFilter` which allows you to capture SQL Statements without running them, e.g:
1249-
12501248
### CaptureSqlFilter
12511249

1252-
[CaptureSqlFilter](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/4c56bde197d07cfc78a80be06dd557732ecf68fa/src/ServiceStack.OrmLite/OrmLiteResultsFilter.cs#L321) is an simple Results Filter which can be used to quickly found out what SQL your DB calls generate by surrounding DB access in a using scope like:
1250+
Results filters makes it trivial to implement the `CaptureSqlFilter` which allows you to capture SQL Statements without running them.
1251+
[CaptureSqlFilter](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/4c56bde197d07cfc78a80be06dd557732ecf68fa/src/ServiceStack.OrmLite/OrmLiteResultsFilter.cs#L321)
1252+
is just a simple Results Filter which can be used to quickly found out what SQL your DB calls generate by surrounding DB access in a using scope, e.g:
12531253

12541254
```csharp
12551255
using (var captured = new CaptureSqlFilter())

lib/ServiceStack.Client.dll

0 Bytes
Binary file not shown.

lib/ServiceStack.Common.dll

0 Bytes
Binary file not shown.

src/ServiceStack.OrmLite.SqlServer/ServiceStack.OrmLite.SqlServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="SqlServerExpression.cs" />
105105
<Compile Include="Properties\AssemblyInfo.cs" />
106106
<Compile Include="SqlServerOrmLiteDialectProvider.cs" />
107+
<Compile Include="SqlServerTableHint.cs" />
107108
</ItemGroup>
108109
<ItemGroup>
109110
<ProjectReference Include="..\ServiceStack.OrmLite\ServiceStack.OrmLite.csproj">

src/ServiceStack.OrmLite.SqlServer/SqlServerExpression.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Data;
3+
using System.Linq.Expressions;
34
using System.Text;
45
using ServiceStack.OrmLite.SqlServer.Converters;
56
using ServiceStack.Text;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ServiceStack.OrmLite.SqlServer
2+
{
3+
public class SqlServerTableHint
4+
{
5+
public static JoinFormatDelegate ReadUncommitted = (dialect, tableDef, expr) => "{0} WITH (READUNCOMMITTED) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
6+
public static JoinFormatDelegate ReadCommitted = (dialect, tableDef, expr) => "{0} WITH (READCOMMITTED) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
7+
public static JoinFormatDelegate ReadPast = (dialect, tableDef, expr) => "{0} WITH (READPAST) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
8+
public static JoinFormatDelegate Serializable = (dialect, tableDef, expr) => "{0} WITH (SERIALIZABLE) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
9+
public static JoinFormatDelegate RepeatableRead = (dialect, tableDef, expr) => "{0} WITH (REPEATABLEREAD) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
10+
}
11+
}

src/ServiceStack.OrmLite.SqlServerTests/ServiceStack.OrmLite.SqlServerTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<Compile Include="UpdateTests.cs" />
120120
<Compile Include="UseCase\ComplexJoinWithLimitAndNoOrderByTests.cs" />
121121
<Compile Include="UseCase\ComplexJoinWithLimitAndSpacesInAliasesTests.cs" />
122+
<Compile Include="UseCase\JoinWithHintUseCase.cs" />
122123
<Compile Include="UseCase\TestEntityWithAliases.cs" />
123124
<Compile Include="UseCase\SimpleUseCase.cs" />
124125
<Compile Include="UseCase\TestEntity.cs" />
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
using ServiceStack.DataAnnotations;
9+
using ServiceStack.OrmLite.SqlServer;
10+
using ServiceStack.Text;
11+
12+
namespace ServiceStack.OrmLite.SqlServerTests.UseCase
13+
{
14+
[TestFixture]
15+
public class JoinWithHintUseCase : OrmLiteTestBase
16+
{
17+
[Alias("car")]
18+
class Car
19+
{
20+
21+
[PrimaryKey]
22+
[Alias("car_id")]
23+
[AutoIncrement]
24+
public int CarId { get; set; }
25+
26+
[Alias("car_name")]
27+
public string Name { get; set; }
28+
}
29+
30+
[Alias("car_type")]
31+
class CarType
32+
{
33+
[Alias("car_id")]
34+
public int CarId { get; set; }
35+
36+
[Alias("car_type_name")]
37+
public string CarTypeName { get; set; }
38+
}
39+
40+
class CarTypeJoin
41+
{
42+
public int CarId { get; set; }
43+
public string CarTypeName { get; set; }
44+
}
45+
46+
private static void InitTables(IDbConnection db)
47+
{
48+
db.DropTable<Car>();
49+
db.DropTable<CarType>();
50+
51+
db.CreateTable<Car>();
52+
db.CreateTable<CarType>();
53+
54+
55+
var id1 = db.Insert(new Car { Name = "Subaru" }, true);
56+
var id2 = db.Insert(new Car { Name = "BMW" }, true);
57+
var id3 = db.Insert(new Car { Name = "Nissan" }, true);
58+
59+
db.Insert(new CarType { CarId = (int)id1, CarTypeName = "Sedan" });
60+
db.Insert(new CarType { CarId = (int)id2, CarTypeName = "Coupe" });
61+
db.Insert(new CarType { CarId = (int)id3, CarTypeName = "SUV" });
62+
}
63+
64+
[Test]
65+
public void can_join_with_readuncommitted()
66+
{
67+
using (var db = OpenDbConnection())
68+
{
69+
InitTables(db);
70+
71+
var join = db.From<Car>()
72+
.Join<Car, CarType>((l, r) => l.CarId == r.CarId, SqlServerTableHint.ReadUncommitted);
73+
74+
var selectStatement = join.ToSelectStatement();
75+
selectStatement.Print();
76+
77+
var data = db.Select<CarTypeJoin>(join);
78+
79+
Assert.That(selectStatement.Contains("READUNCOMMITTED"));
80+
}
81+
}
82+
}
83+
}

src/ServiceStack.OrmLite.Sqlite/SqliteExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override object VisitSqlMethodCall(MethodCallExpression m)
5050
statement = string.Format("{0} DESC", quotedColName);
5151
break;
5252
case "As":
53-
statement = string.Format("{0} As {1}", quotedColName,
53+
statement = string.Format("{0} AS {1}", quotedColName,
5454
base.DialectProvider.GetQuotedColumnName(RemoveQuoteFromAlias(args[0].ToString())));
5555
break;
5656
case "Sum":
@@ -67,7 +67,7 @@ protected override object VisitSqlMethodCall(MethodCallExpression m)
6767
statement = string.Format("COUNT(DISTINCT {0})", quotedColName);
6868
break;
6969
default:
70-
throw new NotSupportedException();
70+
return base.VisitSqlMethodCall(m);
7171
}
7272

7373
return new PartialSqlString(statement);

src/ServiceStack.OrmLite/Expressions/Sql.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ public static string Avg(string value)
102102
{
103103
return "AVG({0})".Fmt(value);
104104
}
105+
106+
public static T AllFields<T>(T item)
107+
{
108+
return item;
109+
}
110+
111+
public static string JoinAlias<T>(T property, string tableAlias)
112+
{
113+
return tableAlias;
114+
}
105115
}
106116

107117
}

0 commit comments

Comments
 (0)