当前位置: 首页>>代码示例>>C#>>正文


C# QueryBuilder.GroupBy方法代码示例

本文整理汇总了C#中ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.GroupBy方法的具体用法?C# QueryBuilder.GroupBy怎么用?C# QueryBuilder.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.GroupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteDataForDocument

        /// <summary>
        /// Deletes all data associated to a document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param>
        private void DeleteDataForDocument(IDocument document, object state)
        {
            // 1. Delete all data related to a document
            // 2. Delete all words that have no more mappings

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("IndexDocument");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "DocName");
            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "DocName", document.Name));

            string subQuery = queryBuilder.SelectFrom("IndexWordMapping", new string[] { "Word" });
            subQuery = queryBuilder.GroupBy(subQuery, new string[] { "Word" });
            string query2 = queryBuilder.DeleteFrom("IndexWord");
            query2 = queryBuilder.WhereNotInSubquery(query2, "IndexWord", "Id", subQuery);

            query = queryBuilder.AppendForBatch(query, query2);

            DbCommand command = null;
            if(state != null) command = builder.GetCommand((DbTransaction)state, query, parameters);
            else command = builder.GetCommand(connString, query, parameters);

            // Close only if state is null
            ExecuteNonQuery(command, state == null);
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:32,代码来源:SqlPagesStorageProviderBase.cs

示例2: GetPagesWithAttachments

        /// <summary>
        /// The the names of the pages with attachments.
        /// </summary>
        /// <returns>The names of the pages with attachments.</returns>
        public string[] GetPagesWithAttachments()
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Attachment", new string[] { "Page" });
            query = queryBuilder.GroupBy(query, new[] { "Page" });
            query = queryBuilder.OrderBy(query, new[] { "Page" }, new[] { Ordering.Asc });

            DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<string> result = new List<string>(100);

                while(reader.Read()) {
                    result.Add(reader["Page"] as string);
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:30,代码来源:SqlFilesStorageProviderBase.cs

示例3: GetAllOutgoingLinks

        /// <summary>
        /// Gets all the outgoing links stored.
        /// </summary>
        /// <returns>The outgoing links, in a dictionary in the form page-&gt;outgoing_links.</returns>
        public IDictionary<string, string[]> GetAllOutgoingLinks()
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            // Explicit columns in order to allow usage of GROUP BY
            string query = queryBuilder.SelectFrom("OutgoingLink", new string[] { "Source", "Destination" });
            query = queryBuilder.GroupBy(query, new string[] { "Source", "Destination" });

            DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                Dictionary<string, string[]> result = new Dictionary<string, string[]>(100);

                string prevSource = "|||";
                string source = null;
                List<string> destinations = new List<string>(20);

                while(reader.Read()) {
                    source = reader["Source"] as string;

                    if(source != prevSource) {
                        if(prevSource != "|||") {
                            result.Add(prevSource, destinations.ToArray());
                            destinations.Clear();
                        }
                    }

                    prevSource = source;
                    destinations.Add(reader["Destination"] as string);
                }

                result.Add(prevSource, destinations.ToArray());

                CloseReader(command, reader);

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:46,代码来源:SqlSettingsStorageProviderBase.cs


注:本文中的ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.GroupBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。