DataQuery.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DLinq / Dlinq / DataQuery.cs / 1599186 / DataQuery.cs

                            using System; 
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions; 
using System.Linq;
using System.Reflection; 
using System.Diagnostics; 
using System.Runtime.CompilerServices;
 
namespace System.Data.Linq {
    using System.Data.Linq.Mapping;
    using System.Data.Linq.Provider;
 
    internal sealed class DataQuery : IOrderedQueryable, IQueryProvider, IEnumerable, IOrderedQueryable, IEnumerable, IListSource {
        DataContext context; 
        Expression queryExpression; 
        private IBindingList cachedList;
 
        public DataQuery(DataContext context, Expression expression) {
            this.context = context;
            this.queryExpression = expression;
        } 

        Expression IQueryable.Expression { 
            get { return this.queryExpression; } 
        }
 
        Type IQueryable.ElementType {
            get { return typeof(T); }
        }
 
        [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
        IQueryable IQueryProvider.CreateQuery(Expression expression) { 
            if (expression == null) 
                throw Error.ArgumentNull("expression");
            Type eType = System.Data.Linq.SqlClient.TypeSystem.GetElementType(expression.Type); 
            Type qType = typeof(IQueryable<>).MakeGenericType(eType);
            if (!qType.IsAssignableFrom(expression.Type))
                throw Error.ExpectedQueryableArgument("expression", qType);
            Type dqType = typeof(DataQuery<>).MakeGenericType(eType); 
            return (IQueryable)Activator.CreateInstance(dqType, new object[] { this.context, expression });
        } 
 
        IQueryable IQueryProvider.CreateQuery(Expression expression) {
            if (expression == null) 
                throw Error.ArgumentNull("expression");
            if (!typeof(IQueryable).IsAssignableFrom(expression.Type))
                throw Error.ExpectedQueryableArgument("expression", typeof(IEnumerable));
            return new DataQuery(this.context, expression); 
        }
 
        object IQueryProvider.Execute(Expression expression) { 
            return this.context.Provider.Execute(expression).ReturnValue;
        } 

        S IQueryProvider.Execute(Expression expression) {
            return (S)this.context.Provider.Execute(expression).ReturnValue;
        } 
        IQueryProvider IQueryable.Provider {
            get{ 
                return (IQueryProvider)this; 
            }
        } 

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)this.context.Provider.Execute(this.queryExpression).ReturnValue).GetEnumerator();
        } 

        IEnumerator IEnumerable.GetEnumerator() { 
            return ((IEnumerable)this.context.Provider.Execute(this.queryExpression).ReturnValue).GetEnumerator(); 
        }
 
        bool IListSource.ContainsListCollection {
            get { return false; }
        }
 
        IList IListSource.GetList() {
            if (cachedList == null) { 
                cachedList = GetNewBindingList(); 
            }
            return cachedList; 
        }

        internal IBindingList GetNewBindingList() {
            return BindingList.Create(this.context, this); 
        }
 
        public override string ToString() { 
            return this.context.Provider.GetQueryText(this.queryExpression);
        } 
    }
}

// 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.ComponentModel;
using System.Linq.Expressions; 
using System.Linq;
using System.Reflection; 
using System.Diagnostics; 
using System.Runtime.CompilerServices;
 
namespace System.Data.Linq {
    using System.Data.Linq.Mapping;
    using System.Data.Linq.Provider;
 
    internal sealed class DataQuery : IOrderedQueryable, IQueryProvider, IEnumerable, IOrderedQueryable, IEnumerable, IListSource {
        DataContext context; 
        Expression queryExpression; 
        private IBindingList cachedList;
 
        public DataQuery(DataContext context, Expression expression) {
            this.context = context;
            this.queryExpression = expression;
        } 

        Expression IQueryable.Expression { 
            get { return this.queryExpression; } 
        }
 
        Type IQueryable.ElementType {
            get { return typeof(T); }
        }
 
        [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
        IQueryable IQueryProvider.CreateQuery(Expression expression) { 
            if (expression == null) 
                throw Error.ArgumentNull("expression");
            Type eType = System.Data.Linq.SqlClient.TypeSystem.GetElementType(expression.Type); 
            Type qType = typeof(IQueryable<>).MakeGenericType(eType);
            if (!qType.IsAssignableFrom(expression.Type))
                throw Error.ExpectedQueryableArgument("expression", qType);
            Type dqType = typeof(DataQuery<>).MakeGenericType(eType); 
            return (IQueryable)Activator.CreateInstance(dqType, new object[] { this.context, expression });
        } 
 
        IQueryable IQueryProvider.CreateQuery(Expression expression) {
            if (expression == null) 
                throw Error.ArgumentNull("expression");
            if (!typeof(IQueryable).IsAssignableFrom(expression.Type))
                throw Error.ExpectedQueryableArgument("expression", typeof(IEnumerable));
            return new DataQuery(this.context, expression); 
        }
 
        object IQueryProvider.Execute(Expression expression) { 
            return this.context.Provider.Execute(expression).ReturnValue;
        } 

        S IQueryProvider.Execute(Expression expression) {
            return (S)this.context.Provider.Execute(expression).ReturnValue;
        } 
        IQueryProvider IQueryable.Provider {
            get{ 
                return (IQueryProvider)this; 
            }
        } 

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)this.context.Provider.Execute(this.queryExpression).ReturnValue).GetEnumerator();
        } 

        IEnumerator IEnumerable.GetEnumerator() { 
            return ((IEnumerable)this.context.Provider.Execute(this.queryExpression).ReturnValue).GetEnumerator(); 
        }
 
        bool IListSource.ContainsListCollection {
            get { return false; }
        }
 
        IList IListSource.GetList() {
            if (cachedList == null) { 
                cachedList = GetNewBindingList(); 
            }
            return cachedList; 
        }

        internal IBindingList GetNewBindingList() {
            return BindingList.Create(this.context, this); 
        }
 
        public override string ToString() { 
            return this.context.Provider.GetQueryText(this.queryExpression);
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK