Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- WebPartConnectionsConnectVerb.cs
- MarshalByRefObject.cs
- ToolboxItemCollection.cs
- SignerInfo.cs
- MetadataPropertyvalue.cs
- XsdDateTime.cs
- ViewDesigner.cs
- DataServiceBehavior.cs
- DbConnectionPoolGroupProviderInfo.cs
- TextCompositionEventArgs.cs
- CategoryNameCollection.cs
- DebuggerAttributes.cs
- GACMembershipCondition.cs
- BaseResourcesBuildProvider.cs
- FlowDocumentPaginator.cs
- Parameter.cs
- SecureConversationServiceCredential.cs
- QilExpression.cs
- ReadOnlyCollectionBase.cs
- WindowVisualStateTracker.cs
- RequestCachePolicyConverter.cs
- SessionParameter.cs
- Expressions.cs
- Registry.cs
- DbResourceAllocator.cs
- ListViewDeletedEventArgs.cs
- StatusBarItem.cs
- AttributeConverter.cs
- QueryCursorEventArgs.cs
- NumberFormatInfo.cs
- _CookieModule.cs
- Light.cs
- ArraySubsetEnumerator.cs
- PlatformCulture.cs
- DocumentViewerAutomationPeer.cs
- SecurityToken.cs
- PassportPrincipal.cs
- PageThemeBuildProvider.cs
- BamlRecords.cs
- BindingNavigatorDesigner.cs
- HttpContext.cs
- ParentUndoUnit.cs
- DataGridViewRowCollection.cs
- StoreItemCollection.Loader.cs
- SourceInterpreter.cs
- CroppedBitmap.cs
- Setter.cs
- MouseButton.cs
- ToolStripInSituService.cs
- RegionInfo.cs
- BinaryFormatter.cs
- _StreamFramer.cs
- ListDictionary.cs
- ObjectKeyFrameCollection.cs
- DbInsertCommandTree.cs
- DBSchemaTable.cs
- ManipulationDevice.cs
- OverloadGroupAttribute.cs
- HtmlTitle.cs
- ComponentRenameEvent.cs
- ObjectSecurity.cs
- TextDecorationUnitValidation.cs
- _OverlappedAsyncResult.cs
- XmlBufferedByteStreamReader.cs
- ScaleTransform.cs
- MemoryFailPoint.cs
- ListViewItemMouseHoverEvent.cs
- HttpException.cs
- WebAdminConfigurationHelper.cs
- Geometry3D.cs
- InternalCache.cs
- ProjectionPruner.cs
- RSAOAEPKeyExchangeFormatter.cs
- IFormattable.cs
- ToolStripControlHost.cs
- RemoteWebConfigurationHost.cs
- NonVisualControlAttribute.cs
- LinkedResourceCollection.cs
- XmlHelper.cs
- FontFamily.cs
- TreeSet.cs
- TCPClient.cs
- CheckedListBox.cs
- BuildManager.cs
- WorkflowInstance.cs
- HttpDebugHandler.cs
- SQLChars.cs
- DistinctQueryOperator.cs
- IntranetCredentialPolicy.cs
- sqlmetadatafactory.cs
- SqlDataSourceCache.cs
- DecoderFallback.cs
- Instrumentation.cs
- AbsoluteQuery.cs
- MessageParameterAttribute.cs
- EventDescriptorCollection.cs
- SystemEvents.cs
- ScriptingProfileServiceSection.cs
- HealthMonitoringSection.cs
- TraceLog.cs