public string BarProperty { get; set; }
}
public class Foo
{
[PrimaryKey]
public int Id { get; set; }
public string FooProperty { get; set; }
}
public class BarView
{
public string BarProperty { get; set; }
public string FooProperty { get; set; }
}
[Test]
public void JoinSqlBuilderWithWhereCondition()
{
IDialectProvider dialectProvider = new SqliteDialectProvider();
using (OrmConnection connection = dialectProvider.CreateConnection(":memory:"))
{
connection.Open();
connection.CreateTable<Bar>(true);
for (int i = 0; i < 10; i++)
{
connection.Insert(new Bar { Id = i, BarProperty = i + "_Bar" });
}
connection.CreateTable<Foo>(true);
for (int i = 0; i < 10; i++)
{
connection.Insert(new Foo { Id = i, FooProperty = i + "_Foo" });
}
var builder = new JoinSqlBuilder<Bar, Bar>(dialectProvider)
.Join<Bar, Foo>(x => x.Id, x => x.Id)
.Select<Bar>(x => new {x.BarProperty})
.Select<Foo>(x => new {x.FooProperty})
.Where<Bar>(x => x.Id > 5);
IList<BarView> views = connection.Query<BarView>(builder.ToSql()).ToList();
Assert.AreEqual(4, views.Count);
foreach (var view in views)
{
Assert.AreEqual(view.BarProperty.Replace("_Bar", string.Empty), view.FooProperty.Replace("_Foo", string.Empty));
}
connection.Close();
}
}