public class GroupByTester
{
public IDbConnectionFactory DbFactory { get; set; }
public GroupByTester()
{
using (var db = DbFactory.Open())
{
//Delegate 'Expression<Func<T1, T2>>' does not take 2 arguments
//'SqlExpression<T1>' does not contain a definition for 'GroupBy'
//and the best extension method overload
//'Queryable.GroupBy<T1, T2>(IQueryable<T1>, Expression<Func<T1, T2>>)'
//requires a receiver of type 'IQueryable<T1>'
db.From<T1>()
.LeftJoin<T2>()
.GroupBy<T1, T2>((t1, t2) => new { t1.X, t2.Y })
}
}
}
public class T1
{
public int Id { get; set; }
public string X { get; set; }
public int Z { get; set; }
}
public class T2
{
public int Id { get; set; }
public int T1Id { get; set; }
public string Y { get; set; }
}
Currently I have workaround like this (created reference of T1 in T2 class):
public class GroupByTester
{
public IDbConnectionFactory DbFactory { get; set; }
public GroupByTester()
{
using (var db = DbFactory.Open())
{
db.From<T1>()
.LeftJoin<T2>()
.GroupBy<T2>(t2 => new { t2.T1.X, t2.Y })
.Select<T1, T2>((t1, t2) => new
{
t1.X,
t2.Y,
SumZ = Sql.Sum(t1.Z)
});
}
}
}
public class T1
{
public int Id { get; set; }
public string X { get; set; }
public int Z { get; set; }
}
public class T2
{
public int Id { get; set; }
public int T1Id { get; set; }
public string Y { get; set; }
[Reference]
public T1 T1 { get; set; }
}