/// <summary>
        /// Joins the nodes in a graph instructing the builder to use the specified synonym for the join query in the relational code.
        /// </summary>
        /// <typeparam name="T">The type of a synonym node.</typeparam>
        /// <param name="graph">A graph.</param>
        /// <param name="synonym">A synonym of a graph.</param>
        public static DbTable <T> JoinAs <T>(this ISemantic graph, DbTable <T> synonym)
            where T : DbRow
        {
            graph.CheckNullAndThrow(Text.Free.Graph, Text.Method.Join);
            synonym.CheckNullAndThrow("synonym", Text.Method.Join);

            CheckSynonymAndThrow(synonym);

            var  node  = graph.Subject;
            bool found = false;

            do
            {
                if (((DbNode)(object)synonym).Equals(node))
                {
                    found = true;
                    break;
                }
            } while ((node = node.Next) != null);
            if (!found)
            {
                throw new QueryTalkException(".JoinAs<T>", QueryTalkExceptionType.InvalidSynonym,
                                             String.Format("synonym = {0}", synonym), Text.Method.JoinSynonym);
            }

            return(((IEndView)((ISemqToSql)graph).Join()
                    .Select("1.*"))
                   .UseAs(synonym));
        }
 /// <summary>
 /// Instructs the builder to use the specified synonym for a node in the relational code.
 /// (For example, a base table can be used as a synonym of a view.)
 /// </summary>
 /// <typeparam name="T">The type of a node.</typeparam>
 /// <param name="node">A node whose synonym is to be used.</param>
 /// <param name="synonym">A synonym of a node.</param>
 public static DbTable <T> UseAs <T>(this DbTable <T> node, ITable synonym)
     where T : DbRow
 {
     node.CheckNullAndThrow("node", Text.Method.UseAs);
     synonym.CheckNullAndThrow("synonym", Text.Method.UseAs);
     ((DbNode)node).Synonym = (DbNode)synonym;
     return(node);
 }
示例#3
0
        /// <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);
        }
        /// <summary>
        /// Instructs the builder to use the specified synonym for a View object in the relational code.
        /// </summary>
        /// <typeparam name="T">The type of a synonym node.</typeparam>
        /// <param name="prev">A View object.</param>
        /// <param name="synonym">A synonym of a query.</param>
        public static DbTable <T> UseAs <T>(this View prev, DbTable <T> synonym)
            where T : DbRow
        {
            prev.CheckNullAndThrow("prev", Text.Method.UseAs);
            synonym.CheckNullAndThrow("synonym", Text.Method.UseAs);

            CheckSynonymAndThrow(synonym);

            ((DbNode)(object)synonym).SynonymQuery = (Chainer)prev;
            return(synonym);
        }
        /// <summary>
        /// Instructs the builder to use the specified synonym for a query in the relational code.
        /// </summary>
        /// <typeparam name="T">The type of a synonym node.</typeparam>
        /// <param name="prev">A SQL query.</param>
        /// <param name="synonym">A synonym of a query.</param>
        public static DbTable <T> UseAs <T>(this IEndView prev, DbTable <T> synonym)
            where T : DbRow
        {
            prev.CheckNullAndThrow("prev", Text.Method.UseAs);
            synonym.CheckNullAndThrow("synonym", Text.Method.UseAs);

            CheckSynonymAndThrow(synonym);
            if (((Chainer)prev).GetRoot().Statements.Count > 1)
            {
                throw new QueryTalkException(".UseAs", QueryTalkExceptionType.InvalidSynonym, null, Text.Method.UseAs);
            }

            ((DbNode)(object)synonym).SynonymQuery = (Chainer)prev;
            return(synonym);
        }
 /// <summary>
 /// Opens the testing environment window. When closed the execution proceeds. The testing does not affect the data state of the execution.
 /// </summary>
 /// <typeparam name="T">The type of a subject node.</typeparam>
 /// <param name="node">A semantic sentence.</param>
 /// <param name="title">A title that will appear in the window.</param>
 /// <param name="option">An option that specifies whether the testing environment window should open, should open and execute, or should be skipped.</param>
 public static DbTable <T> Test <T>(this DbTable <T> node, string title, TestingOption option = TestingOption.OpenAndExecute)
     where T : DbRow
 {
     node.CheckNullAndThrow(Text.Free.Sentence, Text.Method.Test);
     return(_Test(Assembly.GetCallingAssembly(), node, title, option));
 }