Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DLinq / Dlinq / CompiledQuery.cs / 1 / CompiledQuery.cs
using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using System.Linq.Expressions; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Xml; using System.Transactions; using System.Data.Linq.Provider; using System.Diagnostics.CodeAnalysis; namespace System.Data.Linq { public sealed class CompiledQuery { LambdaExpression query; ICompiledQuery compiled; private CompiledQuery(LambdaExpression query) { this.query = query; } public LambdaExpression Expression { get { return this.query; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static FuncCompile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } private static bool UseExpressionCompile(LambdaExpression query) { return typeof(ITable).IsAssignableFrom(query.Body.Type); } private TResult Invoke (TArg0 arg0) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0}); } private TResult Invoke (TArg0 arg0, TArg1 arg1) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1}); } private TResult Invoke (TArg0 arg0, TArg1 arg1, TArg2 arg2) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1, arg2}); } private TResult Invoke (TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1, arg2, arg3}); } private object ExecuteQuery(DataContext context, object[] args) { if (context == null) { throw Error.ArgumentNull("context"); } if (this.compiled == null) { lock (this) { if (this.compiled == null) { this.compiled = context.Provider.Compile(this.query); } } } return this.compiled.Execute(context.Provider, args).ReturnValue; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using System.Linq.Expressions; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Xml; using System.Transactions; using System.Data.Linq.Provider; using System.Diagnostics.CodeAnalysis; namespace System.Data.Linq { public sealed class CompiledQuery { LambdaExpression query; ICompiledQuery compiled; private CompiledQuery(LambdaExpression query) { this.query = query; } public LambdaExpression Expression { get { return this.query; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "[....]: Generic types are an important part of Linq APIs and they could not exist without nested generic support.")] public static Func Compile (Expression > query) where TArg0 : DataContext { if (query == null) { Error.ArgumentNull("query"); } if (UseExpressionCompile(query)) { return query.Compile(); } else { return new CompiledQuery(query).Invoke ; } } private static bool UseExpressionCompile(LambdaExpression query) { return typeof(ITable).IsAssignableFrom(query.Body.Type); } private TResult Invoke (TArg0 arg0) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0}); } private TResult Invoke (TArg0 arg0, TArg1 arg1) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1}); } private TResult Invoke (TArg0 arg0, TArg1 arg1, TArg2 arg2) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1, arg2}); } private TResult Invoke (TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3) where TArg0 : DataContext { return (TResult) this.ExecuteQuery(arg0, new object[] {arg0, arg1, arg2, arg3}); } private object ExecuteQuery(DataContext context, object[] args) { if (context == null) { throw Error.ArgumentNull("context"); } if (this.compiled == null) { lock (this) { if (this.compiled == null) { this.compiled = context.Provider.Compile(this.query); } } } return this.compiled.Execute(context.Provider, args).ReturnValue; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AlternateViewCollection.cs
- RootProfilePropertySettingsCollection.cs
- ParameterBuilder.cs
- PowerModeChangedEventArgs.cs
- EntryIndex.cs
- BindingContext.cs
- Registry.cs
- PasswordTextContainer.cs
- SizeChangedInfo.cs
- ReplyChannelBinder.cs
- DataControlButton.cs
- PeerNeighborManager.cs
- DbConnectionPoolGroupProviderInfo.cs
- HMACSHA512.cs
- HttpWebRequestElement.cs
- DataControlPagerLinkButton.cs
- EditorZone.cs
- BaseParagraph.cs
- ModelItemKeyValuePair.cs
- View.cs
- FileUpload.cs
- SafeEventHandle.cs
- SamlDelegatingWriter.cs
- ClientSettings.cs
- BufferBuilder.cs
- AuthorizationRule.cs
- ProjectionPlanCompiler.cs
- FormViewPageEventArgs.cs
- Converter.cs
- GenericUI.cs
- DecodeHelper.cs
- WebPart.cs
- ContainerUtilities.cs
- ChtmlTextWriter.cs
- DetailsViewDeletedEventArgs.cs
- RecognizerStateChangedEventArgs.cs
- UxThemeWrapper.cs
- HostingPreferredMapPath.cs
- MultipartIdentifier.cs
- StateRuntime.cs
- VisualBasicSettingsHandler.cs
- COM2IPerPropertyBrowsingHandler.cs
- X509Extension.cs
- CommentEmitter.cs
- _FtpControlStream.cs
- DataServiceExpressionVisitor.cs
- ComEventsInfo.cs
- XmlDataSource.cs
- TempFiles.cs
- DocumentsTrace.cs
- MarkupObject.cs
- UIElementParaClient.cs
- PreservationFileWriter.cs
- WindowsScrollBarBits.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- SortQueryOperator.cs
- WhitespaceRuleLookup.cs
- MSAANativeProvider.cs
- WebServiceMethodData.cs
- ExpressionDumper.cs
- userdatakeys.cs
- DataGridViewComboBoxEditingControl.cs
- ACE.cs
- UpdatePanelTrigger.cs
- CAGDesigner.cs
- PackageRelationshipCollection.cs
- ContextMenuService.cs
- ParserStreamGeometryContext.cs
- InternalBufferOverflowException.cs
- LassoSelectionBehavior.cs
- TriggerAction.cs
- DataGridViewTextBoxCell.cs
- _CacheStreams.cs
- ToolstripProfessionalRenderer.cs
- NumericUpDown.cs
- ChildTable.cs
- SlipBehavior.cs
- PagedDataSource.cs
- SelectionEditor.cs
- clipboard.cs
- TimeManager.cs
- BitmapEffectDrawing.cs
- Double.cs
- QuaternionConverter.cs
- ListBindingConverter.cs
- CustomAssemblyResolver.cs
- InheritanceRules.cs
- HttpBindingExtension.cs
- DbgUtil.cs
- MediaScriptCommandRoutedEventArgs.cs
- ConfigUtil.cs
- XmlElementAttributes.cs
- CheckBoxStandardAdapter.cs
- DataKeyArray.cs
- TextElementEnumerator.cs
- XmlSecureResolver.cs
- CodeDomConfigurationHandler.cs
- Point3DIndependentAnimationStorage.cs
- AnimationLayer.cs
- ContextStack.cs