public static void MakeNewNaturalJoinQuery() { var query = new SqlQueryExpression(); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*"))); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b.*"))); query.From.Table(ObjectName.Parse("table1"), "a"); query.From.Table(ObjectName.Parse("table2"), "b"); var expected = new SqlStringBuilder(); expected.AppendLine("SELECT a.*, b.*"); expected.Append(" FROM table1 AS a, table2 AS b"); Assert.Equal(expected.ToString(), query.ToString()); }
public static void CreateNewSimpleQuery() { var query = new SqlQueryExpression(); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*"))); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b"))); query.From.Table(ObjectName.Parse("tab1")); var expected = new SqlStringBuilder(); expected.AppendLine("SELECT a.*, b"); expected.Append(" FROM tab1"); Assert.False(query.From.IsEmpty); Assert.Equal(expected.ToString(), query.ToString()); }
public static void MakeNewInnerJoinQuery() { var query = new SqlQueryExpression(); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*"))); query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b.*"))); query.From.Table(ObjectName.Parse("table1"), "a"); query.From.Join(JoinType.Inner, SqlExpression.Equal(SqlExpression.Reference(ObjectName.Parse("a.id")), SqlExpression.Reference(ObjectName.Parse("b.a_id")))); query.From.Table(ObjectName.Parse("table2"), "b"); var expected = new SqlStringBuilder(); expected.AppendLine("SELECT a.*, b.*"); expected.Append(" FROM table1 AS a INNER JOIN table2 AS b ON a.id = b.a_id"); Assert.Equal(expected.ToString(), query.ToString()); }