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
- InstallerTypeAttribute.cs
- TableRow.cs
- ExtenderProvidedPropertyAttribute.cs
- CreateUserWizardStep.cs
- Connector.xaml.cs
- PagedControl.cs
- CacheEntry.cs
- RequestContext.cs
- KeyInterop.cs
- _Semaphore.cs
- NumberFormatter.cs
- SupportingTokenListenerFactory.cs
- TypeToArgumentTypeConverter.cs
- EllipseGeometry.cs
- UIElementParaClient.cs
- RequestCacheManager.cs
- TextAdaptor.cs
- ThaiBuddhistCalendar.cs
- XmlSchemaAttributeGroupRef.cs
- PathSegmentCollection.cs
- SQLMoneyStorage.cs
- ListenDesigner.cs
- SelectedDatesCollection.cs
- XPathScanner.cs
- RelatedCurrencyManager.cs
- ActivityMarkupSerializer.cs
- HttpCacheVaryByContentEncodings.cs
- Vector3DCollectionConverter.cs
- ExtensionFile.cs
- MouseWheelEventArgs.cs
- SchemaImporterExtensionElementCollection.cs
- HostingPreferredMapPath.cs
- DictionaryKeyPropertyAttribute.cs
- LabelLiteral.cs
- Dump.cs
- SelectionProviderWrapper.cs
- CapabilitiesPattern.cs
- XmlObjectSerializerReadContextComplex.cs
- HtmlControl.cs
- ConsoleTraceListener.cs
- Soap.cs
- HiddenField.cs
- SuppressIldasmAttribute.cs
- RayMeshGeometry3DHitTestResult.cs
- SpecularMaterial.cs
- CultureInfo.cs
- DesignerLoader.cs
- Figure.cs
- CachedBitmap.cs
- HotSpot.cs
- InternalConfigHost.cs
- Int32Rect.cs
- ProgressBarHighlightConverter.cs
- ColumnCollection.cs
- LineBreakRecord.cs
- Int16AnimationBase.cs
- PropertySourceInfo.cs
- FastEncoderWindow.cs
- CodeDomConfigurationHandler.cs
- Focus.cs
- WindowsSpinner.cs
- EntityConnection.cs
- HtmlWindowCollection.cs
- XmlSerializationGeneratedCode.cs
- FileReader.cs
- DayRenderEvent.cs
- Vars.cs
- DataGridAutoFormat.cs
- StringValidatorAttribute.cs
- CurrentChangedEventManager.cs
- Error.cs
- AssemblyAssociatedContentFileAttribute.cs
- SBCSCodePageEncoding.cs
- AnnotationHighlightLayer.cs
- RightsManagementPermission.cs
- RTLAwareMessageBox.cs
- SqlTypeSystemProvider.cs
- FormViewPageEventArgs.cs
- HotSpotCollection.cs
- SapiInterop.cs
- Utils.cs
- AttributeEmitter.cs
- PageParser.cs
- TrackingAnnotationCollection.cs
- UTF7Encoding.cs
- IChannel.cs
- AttachedProperty.cs
- PointAnimationBase.cs
- InvokeBinder.cs
- XmlUrlResolver.cs
- EncryptedXml.cs
- NotifyParentPropertyAttribute.cs
- XmlILIndex.cs
- LogWriteRestartAreaAsyncResult.cs
- Italic.cs
- SecurityDescriptor.cs
- ISO2022Encoding.cs
- PerfCounterSection.cs
- ToolStripComboBox.cs
- GeneralTransform2DTo3DTo2D.cs