Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWebControls / System / Data / WebControls / EntityDataSourceQueryBuilder.cs / 1 / EntityDataSourceQueryBuilder.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Data.Objects;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web.DynamicData;
using System.Web.UI;
namespace System.Web.UI.WebControls
{
internal abstract class EntityDataSourceQueryBuilder
{
private readonly DataSourceSelectArguments _arguments;
private readonly string _commandText;
private readonly ObjectParameter[] _commandParameters;
private readonly string _whereExpression;
private readonly ObjectParameter[] _whereParameters;
private readonly string _entitySetQueryExpression;
private readonly OrderByBuilder _orderByBuilder;
private string _includePaths;
private TypeUsage _resultType;
private Nullable _count;
protected EntityDataSourceQueryBuilder(DataSourceSelectArguments arguments,
string commandText, ObjectParameter[] commandParameters,
string whereExpression, ObjectParameter[] whereParameters, string entitySetQueryExpression,
string selectExpression, string groupByExpression, ObjectParameter[] selectParameters,
OrderByBuilder orderByBuilder,
string includePaths)
{
_arguments = arguments;
_commandText = commandText;
_commandParameters = commandParameters;
_whereExpression = whereExpression;
_whereParameters = whereParameters;
_entitySetQueryExpression = entitySetQueryExpression;
_orderByBuilder = orderByBuilder;
_includePaths = includePaths;
}
internal delegate EntityDataSourceQueryBuilder Creator(DataSourceSelectArguments arguments,
string commandText, ObjectParameter[] commandParameters,
string whereExpression, ObjectParameter[] whereParameters, string entitySetQueryExpression,
string selectExpression, string groupByExpression, ObjectParameter[] selectParameters,
OrderByBuilder orderByBuilder,
string includePaths);
internal TypeUsage ResultType
{
get
{
Debug.Assert(_resultType != null, "ResultType is only valid after Build()");
return _resultType;
}
}
internal int TotalCount
{
get
{
Debug.Assert(_count.HasValue, "Count is not valid until after Build. And only then if computeCount is true");
return _count.Value;
}
}
internal IEnumerable Execute(ObjectQuery queryT)
{
return (IEnumerable)(((IListSource)(queryT)).GetList());
}
internal ObjectQuery Build(ObjectContext context, bool computeCount)
{
ObjectQuery queryT = QueryBuilderUtils.ConstructQuery(context, _entitySetQueryExpression, _commandText, _commandParameters);
queryT = ApplyWhere(queryT);
queryT = ApplySelect(queryT); //Select and/or GroupBy application
if (computeCount)
{
_count = queryT.Count();
}
_resultType = queryT.GetResultType();
queryT = ApplyOrderByAndPaging(queryT);
queryT = ApplyIncludePaths(queryT);
return queryT;
}
private ObjectQuery ApplyWhere(ObjectQuery queryT)
{
if (!String.IsNullOrEmpty(_whereExpression))
{
queryT = queryT.Where(_whereExpression, _whereParameters);
}
return queryT;
}
protected abstract ObjectQuery ApplySelect(ObjectQuery queryT);
private ObjectQuery ApplyOrderByAndPaging(ObjectQuery queryT)
{
string orderByClause;
ObjectParameter[] orderByParameters;
_orderByBuilder.Generate(_resultType, out orderByClause, out orderByParameters);
if ((_arguments.MaximumRows > 0) && (_arguments.StartRowIndex >= 0))
{
if (String.IsNullOrEmpty(orderByClause))
{
throw new InvalidOperationException(Strings.EntityDataSourceQueryBuilder_PagingRequiresOrderBy);
}
queryT = queryT.Skip(orderByClause, _arguments.StartRowIndex.ToString(CultureInfo.InvariantCulture), orderByParameters).Top(_arguments.MaximumRows.ToString(CultureInfo.InvariantCulture), QueryBuilderUtils.EmptyObjectParameters);
}
else if (!string.IsNullOrEmpty(orderByClause))
{
queryT = queryT.OrderBy(orderByClause, orderByParameters);
}
return queryT;
}
private ObjectQuery ApplyIncludePaths(ObjectQuery objectQuery)
{
if (!string.IsNullOrEmpty(_includePaths))
{
foreach (string include in _includePaths.Split(','))
{
string trimmedInclude = include.Trim();
if (!string.IsNullOrEmpty(trimmedInclude))
{
objectQuery = objectQuery.Include(trimmedInclude);
}
}
}
return objectQuery;
}
}
internal class EntityDataSourceObjectQueryBuilder : EntityDataSourceQueryBuilder
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FormViewUpdateEventArgs.cs
- StrokeNodeOperations2.cs
- XmlSchemaAll.cs
- OleAutBinder.cs
- AuthorizationSection.cs
- ToolBar.cs
- XamlPoint3DCollectionSerializer.cs
- DataGridViewComboBoxEditingControl.cs
- KeyEventArgs.cs
- NameSpaceEvent.cs
- Win32SafeHandles.cs
- HelpProvider.cs
- GetKeyedHashRequest.cs
- Clipboard.cs
- XmlSchemaSimpleContentRestriction.cs
- DBCommandBuilder.cs
- COM2TypeInfoProcessor.cs
- XmlSchemaValidator.cs
- CacheHelper.cs
- FontNamesConverter.cs
- LiteralTextParser.cs
- QilParameter.cs
- OrderedDictionary.cs
- ReliableChannelListener.cs
- EnumConverter.cs
- SQLBytesStorage.cs
- HtmlMeta.cs
- XmlSerializer.cs
- SafeThemeHandle.cs
- ScriptIgnoreAttribute.cs
- TdsEnums.cs
- LinqDataSourceValidationException.cs
- SelectionPatternIdentifiers.cs
- XmlNode.cs
- FrameworkObject.cs
- SpeechAudioFormatInfo.cs
- XmlWellformedWriter.cs
- TypeBrowser.xaml.cs
- StructuralCache.cs
- LocationUpdates.cs
- DecimalStorage.cs
- Function.cs
- HttpDebugHandler.cs
- DetailsViewRow.cs
- SqlFunctionAttribute.cs
- InfoCardProofToken.cs
- TrustLevelCollection.cs
- OuterGlowBitmapEffect.cs
- DesignerOptions.cs
- CryptoConfig.cs
- TypeInitializationException.cs
- AutomationPeer.cs
- FrugalMap.cs
- Select.cs
- RenderOptions.cs
- AppearanceEditorPart.cs
- Pen.cs
- IPGlobalProperties.cs
- BitmapEffectDrawingContextState.cs
- AssociationEndMember.cs
- DataGridViewElement.cs
- SafeEventHandle.cs
- HtmlElementCollection.cs
- StrongNameUtility.cs
- RouteValueExpressionBuilder.cs
- AuthenticationModuleElementCollection.cs
- NetworkStream.cs
- ComponentEvent.cs
- ISCIIEncoding.cs
- Matrix3D.cs
- XhtmlBasicTextViewAdapter.cs
- WebDescriptionAttribute.cs
- RegisteredHiddenField.cs
- DeclaredTypeElement.cs
- TraceUtility.cs
- GridViewUpdatedEventArgs.cs
- AuthenticateEventArgs.cs
- SystemInformation.cs
- ConvertEvent.cs
- Vector3dCollection.cs
- DataBoundControl.cs
- SafeMILHandleMemoryPressure.cs
- FixedFlowMap.cs
- RefType.cs
- InputLanguageManager.cs
- AsymmetricAlgorithm.cs
- SmiMetaData.cs
- InteropAutomationProvider.cs
- keycontainerpermission.cs
- StrokeRenderer.cs
- DataServiceRequestArgs.cs
- EventLogPermissionHolder.cs
- LayoutExceptionEventArgs.cs
- SoapCodeExporter.cs
- Compiler.cs
- LogPolicy.cs
- TextRunTypographyProperties.cs
- Permission.cs
- XamlVector3DCollectionSerializer.cs
- GeometryGroup.cs