// a ctor for .WhereExists support internal ConditionChainer(Chainer prev, INonSelectView nonSelectView, bool exists, PredicateGroup predicateGroup = null) : this(prev, predicateGroup) { CheckNullAndThrow(Arg(() => nonSelectView, nonSelectView)); SelectChainer select = new SelectChainer((Chainer)nonSelectView, new Column[] { Designer.Null }, false); var view = new View(select, Query); Query.AddArguments(view.Query.Arguments.ToArray()); Build = (buildContext, buildArgs) => { string keyword = exists ? Text.Exists : Text.NotExists; var sql = Text.GenerateSql(100) .NewLine(predicateGroup.Build(PredicateGroupType.Begin, Keyword)).S() .Append(prev.ExpressionGroupType.IsBegin() ? Text.LeftBracket : null) .Append(keyword).S() .EncloseLeft() .Append(view.Build(buildContext, buildArgs)) .EncloseRight() .Append(prev.ExpressionGroupType.IsEnd() ? Text.RightBracket : null) .Append(predicateGroup.Build(PredicateGroupType.End, null)) .S(); TryThrow(buildContext); return(sql.ToString()); }; }
private static DbTable <T> _Test <T>(Assembly ca, DbTable <T> node, string title, TestingOption option) where T : DbRow { if (Admin.IsTestingEnvironmentOff(ca) || option == TestingOption.Skip) { return(node); } // handle reusability - ! var node2 = node.RootWithBrokenChain ?? node.Root; Chainer query; if (node2.IsPureSubject()) { query = new SelectChainer((ISemantic)node2, new Column[] { }, false).Top(Admin.TestSelectTopRows); } else { query = new SelectChainer((ISemantic)node2, new Column[] { }, false); } var connectable = Reader.GetConnectable(ca, query); using (var form = new TestingForm(connectable, option, title)) { form.ShowDialog(); } node2.Recover(); return(node); }
/// <summary> /// Returns the number of the rows returned by a semantic query. /// </summary> /// <typeparam name="T">The type of the subject node.</typeparam> /// <param name="prev">Is a subject node.</param> public static int CountGo <T>(this DbTable <T> prev) where T : DbRow { prev.CheckNullAndThrow(Text.Free.Sentence, Text.Method.SelectCount); var ca = Assembly.GetCallingAssembly(); var select = new SelectChainer((ISemantic)prev, new Column[] { Designer.Count().As(Text.Count) }, false); var connectable = Reader.GetConnectable(ca, select); return(Reader.LoadTable <Row <int> >(connectable, null).ToValue <int>()); }
/// <summary> /// Returns true if a semantic query contains any rows. /// </summary> /// <typeparam name="T">The type of the subject node.</typeparam> /// <param name="prev">A semantic query.</param> /// <returns></returns> public static bool ExistsGo <T>(this DbTable <T> prev) where T : DbRow { prev.CheckNullAndThrow(Text.Free.Sentence, Text.Method.ExistsGo); var ca = Assembly.GetCallingAssembly(); var select = new SelectChainer((ISemantic)prev, new Column[] { Designer.Null }, false); var connectable = Reader.GetConnectable(ca, select.TopOne()); var result = Reader.LoadTable <dynamic>(connectable, null); return(result.RowCount > 0); }