Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / ELinq / ObjectQueryProvider.cs / 1305376 / ObjectQueryProvider.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Objects.Internal;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace System.Data.Objects.ELinq
{
///
/// LINQ query provider implementation.
///
internal sealed class ObjectQueryProvider : IQueryProvider
{
private readonly ObjectContext _context;
internal ObjectQueryProvider(ObjectContext context)
{
Debug.Assert(null != context, "context must be given");
_context = context;
}
///
/// Creates a new query instance using the given LINQ expresion.
/// The current query is used to produce the context for the new query, but none of its logic
/// is used.
///
/// Element type for query result.
/// LINQ expression forming the query.
/// ObjectQuery implementing the expression logic.
IQueryable IQueryProvider.CreateQuery(Expression expression)
{
EntityUtil.CheckArgumentNull(expression, "expression");
if (!typeof(IQueryable).IsAssignableFrom(expression.Type))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.ELinq_ExpressionMustBeIQueryable, "expression");
}
ObjectQuery query = CreateQuery(expression);
return query;
}
///
/// Executes the given LINQ expression returning a single value, or null if the query yields
/// no results. If the return type is unexpected, raises a cast exception.
/// The current query is used to produce the context for the new query, but none of its logic
/// is used.
///
/// Type of returned value.
/// Expression to evaluate.
/// Single result from execution.
S IQueryProvider.Execute(Expression expression)
{
EntityUtil.CheckArgumentNull(expression, "expression");
ObjectQuery query = CreateQuery(expression);
return ExecuteSingle(query, expression);
}
///
/// Creates a new query instance using the given LINQ expresion.
/// The current query is used to produce the context for the new query, but none of its logic
/// is used.
///
/// Expression forming the query.
/// ObjectQuery instance implementing the given expression.
IQueryable IQueryProvider.CreateQuery(Expression expression)
{
EntityUtil.CheckArgumentNull(expression, "expression");
if (!typeof(IQueryable).IsAssignableFrom(expression.Type))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.ELinq_ExpressionMustBeIQueryable, "expression");
}
// Determine the type of the query instance by binding generic parameter in Query<>.Queryable
// (based on element type of expression)
Type elementType = TypeSystem.GetElementType(expression.Type);
ObjectQuery query = CreateQuery(expression, elementType);
return query;
}
///
/// Executes the given LINQ expression returning a single value, or null if the query yields
/// no results.
/// The current query is used to produce the context for the new query, but none of its logic
/// is used.
///
/// Expression to evaluate.
/// Single result from execution.
object IQueryProvider.Execute(Expression expression)
{
EntityUtil.CheckArgumentNull(expression, "expression");
ObjectQuery query = CreateQuery(expression, expression.Type);
IEnumerable
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SettingsProperty.cs
- PrintPageEvent.cs
- SiteMapNodeItem.cs
- ToolStripContainerDesigner.cs
- WindowClosedEventArgs.cs
- WebPartConnectionsCloseVerb.cs
- Style.cs
- DataBoundControlAdapter.cs
- CookielessHelper.cs
- DeviceContext.cs
- Context.cs
- InvalidEnumArgumentException.cs
- HtmlControlPersistable.cs
- RepeaterCommandEventArgs.cs
- SequenceFullException.cs
- bidPrivateBase.cs
- ClientType.cs
- X509SecurityTokenProvider.cs
- InkPresenter.cs
- CodeBinaryOperatorExpression.cs
- HtmlValidatorAdapter.cs
- QilUnary.cs
- HttpConfigurationSystem.cs
- TreeBuilder.cs
- InfoCardRSACryptoProvider.cs
- CheckPair.cs
- CodePrimitiveExpression.cs
- CodeDomSerializerBase.cs
- Util.cs
- ConfigurationSectionGroupCollection.cs
- ListViewInsertionMark.cs
- NameValueFileSectionHandler.cs
- TdsParserStaticMethods.cs
- ActivityFunc.cs
- MonthChangedEventArgs.cs
- ConfigurationSettings.cs
- RequestCacheEntry.cs
- GradientSpreadMethodValidation.cs
- CodeIndexerExpression.cs
- XmlAttributeOverrides.cs
- RenderOptions.cs
- ServiceXNameTypeConverter.cs
- SqlConnection.cs
- PolygonHotSpot.cs
- HashStream.cs
- DispatchWrapper.cs
- FixedSOMTableCell.cs
- KeyValuePairs.cs
- DBDataPermission.cs
- StylusDevice.cs
- TextRangeEditLists.cs
- SafeLocalMemHandle.cs
- NameValueFileSectionHandler.cs
- SwitchLevelAttribute.cs
- UpDownEvent.cs
- SmtpFailedRecipientException.cs
- Int64Storage.cs
- DeviceContext.cs
- ObjectDataSourceStatusEventArgs.cs
- NameSpaceExtractor.cs
- MouseGesture.cs
- UnsafeNativeMethods.cs
- IHttpResponseInternal.cs
- WebPartTransformerAttribute.cs
- TextProperties.cs
- ByteRangeDownloader.cs
- UserControl.cs
- COSERVERINFO.cs
- AdRotator.cs
- RtfToXamlReader.cs
- GeneralTransform3DGroup.cs
- WebConfigurationHostFileChange.cs
- PlatformCulture.cs
- CacheRequest.cs
- HttpListenerPrefixCollection.cs
- ConfigurationElementProperty.cs
- MultipleViewProviderWrapper.cs
- Mutex.cs
- TextEditorSelection.cs
- EntityDataSourceViewSchema.cs
- Lazy.cs
- WebPartDisplayMode.cs
- Mutex.cs
- SiblingIterators.cs
- SessionKeyExpiredException.cs
- ProjectedWrapper.cs
- SR.cs
- MessageHeaders.cs
- XmlSchemaAnnotation.cs
- OleDbParameter.cs
- SplashScreen.cs
- SqlWebEventProvider.cs
- XmlSchemaComplexContent.cs
- ManualResetEvent.cs
- EntityClientCacheKey.cs
- NativeObjectSecurity.cs
- WCFModelStrings.Designer.cs
- FrameworkTemplate.cs
- GrowingArray.cs
- InvalidWMPVersionException.cs