public static GroupByOperation GroupBy(this IObservableOperation observed, string[] columns, Action <Row, Row> aggregate = null) { var op = new GroupByOperation(columns, aggregate); observed.Subscribe(op); return(op); }
/// <summary> /// Apply an action on the rows /// </summary> /// <param name="observed">observed operation</param> /// <param name="columns">callback method for the action</param> /// <returns>resulting operation</returns> public static GroupByOperation GroupBy(this IObservableOperation observed, params string[] columns) { var op = new GroupByOperation(columns); observed.Subscribe(op); return(op); }
/// <summary> /// groupby /// </summary> /// <param name="fields"></param> /// <returns></returns> public Search GroupBy(params Field[] fields) { if (null == fields || fields.Length <= 0) { return(this); } var tempgroupby = fields.Aggregate(GroupByOperation.None, (current, f) => current && f.GroupBy); this.groupBy = tempgroupby; return(this); }
public void GroupByOperation() { var c = new ObservableCollection<NotificationObject<string>>() { new NotificationObject<string>() { Value1 = "Group1", Value2 = "Item1" }, new NotificationObject<string>() { Value1 = "Group1", Value2 = "Item2" }, new NotificationObject<string>() { Value1 = "Group1", Value2 = "Item3" }, new NotificationObject<string>() { Value1 = "Group2", Value2 = "Item4" }, new NotificationObject<string>() { Value1 = "Group2", Value2 = "Item5" }, new NotificationObject<string>() { Value1 = "Group2", Value2 = "Item6" }, }; var op = new GroupByOperation<NotificationObject<string>, string>(new OperationContext(), Expression.Call( typeof(Queryable).GetMethods() .Where(i => i.Name == "GroupBy") .Where(i => i.IsGenericMethodDefinition) .Where(i => i.GetGenericArguments().Length == 2) .Select(i => i.MakeGenericMethod(typeof(NotificationObject<string>), typeof(string))) .Where(i => i.GetParameters().Length == 2) .Where(i => i.GetParameters()[1].ParameterType == typeof(Expression<Func<NotificationObject<string>, string>>)) .Single(), new ObservableQuery<NotificationObject<string>>(c).Expression, Expression.Lambda<Func<NotificationObject<string>, string>>( Expression.MakeMemberAccess( Expression.Parameter(typeof(NotificationObject<string>), "p"), typeof(NotificationObject<string>).GetProperty("Value1")), Expression.Parameter(typeof(NotificationObject<string>), "p")))); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(3, op.Value.ToList()[0].Count()); Assert.AreEqual(3, op.Value.ToList()[1].Count()); c.Add(new NotificationObject<string>() { Value1 = "Group1", Value2 = "Item7" }); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(4, op.Value.ToList()[0].Count()); Assert.AreEqual(3, op.Value.ToList()[1].Count()); c.Add(new NotificationObject<string>() { Value1 = "Group2", Value2 = "Item8" }); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(4, op.Value.ToList()[0].Count()); Assert.AreEqual(4, op.Value.ToList()[1].Count()); c[0].Value1 = "Group3"; Assert.AreEqual(3, op.Value.Count()); Assert.AreEqual(3, op.Value.ToList()[0].Count()); Assert.AreEqual(4, op.Value.ToList()[1].Count()); }
/// <summary> /// groupby /// </summary> /// <param name="groupBy"></param> /// <returns></returns> public Search GroupBy(GroupByOperation groupBy) { this.groupBy = groupBy; return(this); }
/// <summary> /// groupby /// </summary> public new Search <T> GroupBy(GroupByOperation groupBy) { return((Search <T>)base.GroupBy(groupBy)); }
public void GroupByOperation() { var c = new ObservableCollection <NotificationObject <string> >() { new NotificationObject <string>() { Value1 = "Group1", Value2 = "Item1" }, new NotificationObject <string>() { Value1 = "Group1", Value2 = "Item2" }, new NotificationObject <string>() { Value1 = "Group1", Value2 = "Item3" }, new NotificationObject <string>() { Value1 = "Group2", Value2 = "Item4" }, new NotificationObject <string>() { Value1 = "Group2", Value2 = "Item5" }, new NotificationObject <string>() { Value1 = "Group2", Value2 = "Item6" }, }; var op = new GroupByOperation <NotificationObject <string>, string>(new OperationContext(), Expression.Call( typeof(Queryable).GetMethods() .Where(i => i.Name == "GroupBy") .Where(i => i.IsGenericMethodDefinition) .Where(i => i.GetGenericArguments().Length == 2) .Select(i => i.MakeGenericMethod(typeof(NotificationObject <string>), typeof(string))) .Where(i => i.GetParameters().Length == 2) .Where(i => i.GetParameters()[1].ParameterType == typeof(Expression <Func <NotificationObject <string>, string> >)) .Single(), new ObservableQuery <NotificationObject <string> >(c).Expression, Expression.Lambda <Func <NotificationObject <string>, string> >( Expression.MakeMemberAccess( Expression.Parameter(typeof(NotificationObject <string>), "p"), typeof(NotificationObject <string>).GetProperty("Value1")), Expression.Parameter(typeof(NotificationObject <string>), "p")))); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(3, op.Value.ToList()[0].Count()); Assert.AreEqual(3, op.Value.ToList()[1].Count()); c.Add(new NotificationObject <string>() { Value1 = "Group1", Value2 = "Item7" }); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(4, op.Value.ToList()[0].Count()); Assert.AreEqual(3, op.Value.ToList()[1].Count()); c.Add(new NotificationObject <string>() { Value1 = "Group2", Value2 = "Item8" }); Assert.AreEqual(2, op.Value.Count()); Assert.AreEqual(4, op.Value.ToList()[0].Count()); Assert.AreEqual(4, op.Value.ToList()[1].Count()); c[0].Value1 = "Group3"; Assert.AreEqual(3, op.Value.Count()); Assert.AreEqual(3, op.Value.ToList()[0].Count()); Assert.AreEqual(4, op.Value.ToList()[1].Count()); }
public void setupFilters() { collection = new ObservableCollection<NOS>() { new NOS( "Group1", "Item1" ), new NOS( "Group1", "Item2" ), new NOS( "Group1", "Item3" ), new NOS( "Group2", "Item4" ), new NOS( "Group2", "Item5" ), new NOS( "Group2", "Item6" ), }; operation = new GroupByOperation<NOS, string>(new OperationContext(), Expression.Call( typeof(Queryable).GetMethods() .Where(i => i.Name == "GroupBy") .Where(i => i.IsGenericMethodDefinition) .Where(i => i.GetGenericArguments().Length == 2) .Select(i => i.MakeGenericMethod(typeof(NOS), typeof(string))) .Where(i => i.GetParameters().Length == 2) .Where(i => i.GetParameters()[1].ParameterType == typeof(Expression<Func<NOS, string>>)) .Single(), new ObservableQuery<NOS>(collection).Expression, Expression.Lambda<Func<NOS, string>>( Expression.MakeMemberAccess( Expression.Parameter(typeof(NOS), "p"), typeof(NOS).GetProperty("Value1")), Expression.Parameter(typeof(NOS), "p")))); buffer = operation.AsObservableQuery().ToObservableView().ToBuffer(); }