internal override IEnumerable <TKey> InMemorySelect(IQueryRunner runner) { var lhs = ParentT.InMemorySelect(runner).ToList(); var rhs = JoinTableTJoin.InMemorySelect(runner).ToList(); var ctx = new SelectorContext <T>(runner, lhs); var joinCtx = new SelectorContext <TJoin>(runner, rhs); foreach (var item in lhs) { var joined = false; var fromRow = ParentT.FromRowMapping[item]; foreach (var joinItem in rhs) { var joinResult = JoinFunction(ctx, item, joinCtx, joinItem); if (joinResult) { joined = true; var result = ResultFunction(ctx, item, joinCtx, joinItem); FromRowMapping[result] = fromRow; yield return(result); } } if (!joined && JoinType == JoinType.LeftJoin) { var result = ResultFunction(ctx, item, joinCtx, default(TJoin)); FromRowMapping[result] = fromRow; yield return(result); } } }
internal override IEnumerable <TProject> InMemorySelect(IQueryRunner runner) { var groups = new Dictionary <TGroup, KeyValuePair <T, List <T> > >(); // var groups = new Dictionary<TGroup, KeyValuePair<TProject, List<T>>>(); foreach (var item in ParentT.InMemorySelect(runner)) { var key = GroupFunction(item); if (!groups.ContainsKey(key)) { var listInstance = new List <T>(); groups[key] = new KeyValuePair <T, List <T> >(item, listInstance); // groups[key] = new KeyValuePair<TProject, List<T>>(project, listInstance); } groups[key].Value.Add(item); } foreach (var key in groups.Keys) { var kv = groups[key]; var context = new SelectorContext <T>(runner, kv.Value); var project = ProjectFunction(context, kv.Key); // FromRowMapping[kv.Key] = ParentT.FromRowMapping[]; yield return(project); } }
TResult InvokeSelectFunction(SelectorContext <T> context, T item) { var result = SelectFunction(context, item); var fromRow = ParentT.FromRowMapping[item]; FromRowMapping[result] = fromRow; return(result); }
internal override IEnumerable <T> InMemorySelect(IQueryRunner runner) { var context = new SelectorContext(runner); return(new List <T>() { SelectFunction(context) }); }
public static double?Sum <T>(SelectorContext <T> t, Func <T, double?> selector) { var result = (double?)0; foreach (var item in t.Items) { result += selector(item); } return(result); }
public static int?Sum <T>(SelectorContext <T> t, Func <T, short?> selector) { var result = (int?)0; foreach (var item in t.Items) { result += selector(item); } return(result); }
TResult InvokeSelectFunction(SelectorContext <T> context, T item) { var result = SelectFunction(context, item); if (Parent is FlatQuery <TFrom, T> ) { var fromRow = ParentT.FromRowMapping[item]; FromRowMapping[result] = fromRow; } return(result); }
public void EvaluateInMemory(IQueryRunner runner) { if (Variable.PlaceholderType == SqlPlaceholderType.SessionVariableName) { var context = new SelectorContext <T>(runner, null); Variable.Value = ValueFunction(context); } else { throw new InvalidOperationException("Uhndlet vrbitype"); } }
public static double?Average <T>(SelectorContext <T> t, Func <T, double?> selector) { var result = (double?)0; var count = 0; foreach (var item in t.Items) { result += selector(item); count++; } return(result / count); }
internal override IEnumerable <TResult> InMemorySelect(IQueryRunner runner) { var parentResult = ParentT.InMemorySelect(runner); var context = new SelectorContext <T>(runner, parentResult.ToList()); // Implicit grouping, f.ex SELECT COUNT(*) FROM tbl if (Parent is FlatQuery <TFrom, T> && HasAggregates(SelectExpression)) { return(parentResult.Select(x => InvokeSelectFunction(context, x)).Take(1)); } return(parentResult.Select(x => InvokeSelectFunction(context, x))); }
public static long?Max <T>(SelectorContext <T> t, Func <T, long?> selector) { var result = (long?)null; foreach (var item in t.Items) { var value = selector(item); if (!result.HasValue) { result = value; } else if (value.HasValue) { result = Math.Max(result.Value, selector(item).Value); } } return(result); }
public static decimal?Min <T>(SelectorContext <T> t, Func <T, decimal?> selector) { var result = (decimal?)null; foreach (var item in t.Items) { var value = selector(item); if (!result.HasValue) { result = value; } else if (value.HasValue) { result = Math.Min(result.Value, selector(item).Value); } } return(result); }
public static string Min <T>(SelectorContext <T> t, Func <T, string> selector) { var result = (string)null; foreach (var item in t.Items) { var value = selector(item); if (result == null) { result = value; } else if (value != null) { var selectorValue = selector(item); result = result.CompareTo(selectorValue) < 0 ? result : selectorValue; } } return(result); }
public static DateTime?Min <T>(SelectorContext <T> t, Func <T, DateTime?> selector) { var result = (DateTime?)null; foreach (var item in t.Items) { var value = selector(item); if (!result.HasValue) { result = value; } else if (value.HasValue) { var selectorValue = selector(item).Value; result = result.Value < selectorValue ? result.Value : selectorValue; } } return(result); }
public static int Count <T, TX>(SelectorContext <T> t, Func <T, TX> selector) { return(t.Items.Count); }
public static T LastInsertIdentity <T>(SelectorContext context) { return((T)((InMemoryQueryRunner)context.Runner).LastIdentity); }
public static bool Contains <T, TResult>(SelectorContext <T> context, TResult value, SelectStatement <TResult> sq) { return(sq.SelectQueryTResult.InMemorySelect((InMemoryQueryRunner)context.Runner).Contains(value)); }