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


C# DataView.GetQuery方法代码示例

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


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

示例1: BindGrid

        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="grid">The grid.</param>
        /// <param name="dataView">The data view.</param>
        /// <returns></returns>
        private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null )
        {
            var errorMessages = new List<string>();
            grid.DataSource = null;

            if ( dataView.EntityTypeId.HasValue )
            {
                var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value );
                if ( cachedEntityType != null && cachedEntityType.AssemblyName != null )
                {
                    Type entityType = cachedEntityType.GetEntityType();

                    if ( entityType != null )
                    {
                        grid.CreatePreviewColumns( entityType );

                        var qry = dataView.GetQuery( grid.SortProperty, out errorMessages );

                        if ( fetchRowCount.HasValue )
                        {
                            qry = qry.Take( fetchRowCount.Value );
                        }

                        grid.DataSource = qry.AsNoTracking().ToList();
                    }
                }
            }

            if ( grid.DataSource != null )
            {
                grid.ExportFilename = dataView.Name;
                if ( errorMessages.Any() )
                {
                    nbEditModeMessage.Text = "INFO: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" );
                }

                if ( dataView.EntityTypeId.HasValue )
                {
                    grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName;
                }

                grid.DataBind();
                return true;
            }

            return false;
        }
开发者ID:jondhinkle,项目名称:Rock,代码行数:53,代码来源:DataViewDetail.ascx.cs

示例2: BindGrid

        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="grid">The grid.</param>
        /// <param name="dataView">The data view.</param>
        /// <returns></returns>
        private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null )
        {
            grid.DataSource = null;

            // Only respect the ShowResults option if fetchRowCount is null
            if ( !this.ShowResults && fetchRowCount == null )
            {
                return false;
            }

            var errorMessages = new List<string>();

            if ( dataView.EntityTypeId.HasValue )
            {
                var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value );
                if ( cachedEntityType != null && cachedEntityType.AssemblyName != null )
                {
                    Type entityType = cachedEntityType.GetEntityType();

                    if ( entityType != null )
                    {
                        try
                        {
                            grid.CreatePreviewColumns( entityType );

                            var qry = dataView.GetQuery( grid.SortProperty, GetAttributeValue( "DatabaseTimeout" ).AsIntegerOrNull() ?? 180, out errorMessages );

                            if ( fetchRowCount.HasValue )
                            {
                                qry = qry.Take( fetchRowCount.Value );
                            }

                            grid.SetLinqDataSource( qry.AsNoTracking() );
                            grid.DataBind();
                        }
                        catch ( Exception ex )
                        {
                            this.LogException( ex );
                            Exception exception = ex;
                            while ( exception != null )
                            {
                                if ( exception is System.Data.SqlClient.SqlException )
                                {
                                    // if there was a SQL Server Timeout, have the warning be a friendly message about that.
                                    if ( ( exception as System.Data.SqlClient.SqlException ).Number == -2 )
                                    {
                                        nbEditModeMessage.NotificationBoxType = NotificationBoxType.Warning;
                                        nbEditModeMessage.Text = "This dataview did not complete in a timely manner. You can try again or adjust the timeout setting of this block.";
                                        return false;
                                    }
                                    else
                                    {
                                        errorMessages.Add( exception.Message );
                                        exception = exception.InnerException;
                                    }
                                }
                                else
                                {
                                    errorMessages.Add( exception.Message );
                                    exception = exception.InnerException;
                                }
                            }
                        }
                    }
                }
            }

            var errorBox = ( grid == gPreview) ? nbPreviewError : nbGridError;

            if ( errorMessages.Any() )
            {
                errorBox.NotificationBoxType = NotificationBoxType.Warning;
                errorBox.Text = "WARNING: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" );
                errorBox.Visible = true;
            }
            else
            {
                errorBox.Visible = false;
            }

            if ( dataView.EntityTypeId.HasValue )
            {
                grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName;
            }

            if ( grid.DataSource != null )
            {
                grid.ExportFilename = dataView.Name;
                return true;
            }

            return false;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:99,代码来源:DataViewDetail.ascx.cs


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