ServiceStack/ServiceStack.OrmLite — pull request #120 by gkathire (2012-12-15 10:35:58+00:00)
Title: New join builder feature

I made an initial attempt to create a join builder with minimal change to the base library.
This patch contains a new JoinBuilder class which can be used to create Sql with multiple tables join together with where and order by clauses. Let me know if this is a candidate for inclusion in the main tree.

Here are some code snippets and the corresponding sqls generated :

```csharp
var jn = new JoinSqlBuilder();
jn = jn.InnerJoin(x => x.UserDataId, x => x.Id, x => new { x.Name, x.Id }, x => new { x.UserDataValue })
.LeftOuterJoin(x => x.UserServiceId, x => x.Id, null, x => new { x.ServiceName })
.OrderBy(x=>x.Id)
.OrderByDescending(x=>x.Name)
.Select(x=>x.Id)
.Where(x=> x.Id == 0);

var sql = jn.ToSql();
```
```sql
SELECT "User"."Name","User"."Id","UserData"."UserDataValue","UserService"."ServiceName","User"."Id"
FROM User
INNER JOIN UserData ON "User"."UserDataId" = "UserData"."Id"
LEFT OUTER JOIN UserService ON "User"."UserServiceId" = "UserService"."Id"
WHERE ("User"."Id" = 0)
ORDER BY "User"."Id" ASC ,"User"."Name" DESC
```

```csharp
jn.Clear();
jn = jn.InnerJoin(x => x.UserDataId, x => x.Id)
.LeftOuterJoin(x => x.UserServiceId, x => x.Id)
.OrderBy(x => x.Id)
.OrderByDescending(x => x.Name)
.Where(x => x.Id > 0)
.Or(x => x.Id < 10)
.And(x => x.Name != "" || x.Name != null);

var sql2 = jn.ToSql();
```

```sql
SELECT "User"."Id","User"."Name",CreatedDate,"UserData"."UserDataValue","UserService"."ServiceName"
FROM User
INNER JOIN UserData ON "User"."UserDataId" = "UserData"."Id"
LEFT OUTER JOIN UserService ON "User"."UserServiceId" = "UserService"."Id"
WHERE ("User"."Id" > 0) OR ("User"."Id" < 10) AND (("User"."Name" <> '') OR ("User"."Name" is not null))
ORDER BY "User"."Id" ASC ,"User"."Name" DESC
```

PS: Even though I have write access to the main trunk, I dont want to checkin this change as I need some more code review and input on this.