本文整理汇总了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;
}
示例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;
}