├── PATENTS.txt
├── src
├── SD.Tools.LinqToDB.snk
├── DbEngines
│ └── SqlServer
│ │ ├── SqlCEProvider.cs
│ │ ├── SqlBooleanizer.cs
│ │ ├── Sql2008Provider.cs
│ │ ├── SqlFormatter.cs
│ │ └── SqlTopReducer.cs
├── Provider
│ ├── Interfaces
│ │ ├── ICompiledSubQuery.cs
│ │ ├── IObjectReaderSession.cs
│ │ ├── IReaderProvider.cs
│ │ ├── IConnectionUser.cs
│ │ ├── IConnectionManager.cs
│ │ ├── IObjectReaderFactory.cs
│ │ ├── IObjectReaderCompiler.cs
│ │ └── IObjectReader.cs
│ ├── NodeTypes
│ │ ├── SqlSource.cs
│ │ ├── SqlStatement.cs
│ │ ├── SqlNop.cs
│ │ ├── SqlIncludeScope.cs
│ │ ├── SqlBlock.cs
│ │ ├── SqlDelete.cs
│ │ ├── SqlDiscriminatorOf.cs
│ │ ├── SqlVariable.cs
│ │ ├── SqlSharedExpressionRef.cs
│ │ ├── SqlClientParameter.cs
│ │ ├── SqlRow.cs
│ │ ├── SqlDoNotVisitExpression.cs
│ │ ├── SqlValue.cs
│ │ ├── SqlStoredProcedureCall.cs
│ │ ├── SqlClientArray.cs
│ │ ├── SqlRowNumber.cs
│ │ ├── SqlAlias.cs
│ │ ├── SqlSimpleTypeExpression.cs
│ │ ├── SqlMemberAssign.cs
│ │ ├── SqlUpdate.cs
│ │ ├── SqlSubSelect.cs
│ │ ├── SqlLift.cs
│ │ ├── SqlSharedExpression.cs
│ │ ├── SqlSimpleExpression.cs
│ │ ├── SqlBetween.cs
│ │ ├── SqlParameter.cs
│ │ ├── SqlIn.cs
│ │ ├── SqlTypeCaseWhen.cs
│ │ ├── SqlUserRow.cs
│ │ ├── SqlFunctionCall.cs
│ │ ├── SqlOptionalValue.cs
│ │ ├── SqlColumnRef.cs
│ │ ├── SqlMember.cs
│ │ ├── SqlUserColumn.cs
│ │ ├── SqlExprSet.cs
│ │ ├── SqlClientQuery.cs
│ │ ├── SqlJoin.cs
│ │ ├── SqlAssign.cs
│ │ ├── SqlDiscriminatedType.cs
│ │ ├── SqlJoinedCollection.cs
│ │ ├── SqlTableValuedFunctionCall.cs
│ │ ├── SqlClientWhen.cs
│ │ ├── SqlTable.cs
│ │ ├── SqlGrouping.cs
│ │ ├── SqlMethodCall.cs
│ │ ├── SqlInsert.cs
│ │ ├── SqlWhen.cs
│ │ ├── SqlNode.cs
│ │ ├── SqlSearchedCase.cs
│ │ ├── SqlExpression.cs
│ │ ├── SqlSimpleCase.cs
│ │ ├── SqlLike.cs
│ │ ├── SqlClientCase.cs
│ │ └── SqlLink.cs
│ ├── Visitors
│ │ ├── ExpectNoAliasRefs.cs
│ │ ├── ExpectNoSharedExpressions.cs
│ │ ├── ProducedAliasGatherer.cs
│ │ ├── ExpectRationalizedBooleans.cs
│ │ ├── Funcletizer.cs
│ │ ├── ProducedColumnsGatherer.cs
│ │ ├── ExpectNoFloatingColumns.cs
│ │ ├── SubqueryValidator.cs
│ │ ├── ColumnNameGatherer.cs
│ │ ├── SideEffectChecker.cs
│ │ ├── ExpectNoMethodCalls.cs
│ │ ├── LiteralValidator.cs
│ │ ├── MultiSetDetector.cs
│ │ ├── ConsumedAliaseGatherer.cs
│ │ ├── SqlSupersetValidator.cs
│ │ ├── ColumnTypeValidator.cs
│ │ ├── SqlSelectionSkipper.cs
│ │ ├── ColumnDeclarer.cs
│ │ ├── QueryHierarchyFinder.cs
│ │ ├── DependenceChecker.cs
│ │ ├── ValidateNoInvalidComparison.cs
│ │ ├── ConstantInOrderByRemover.cs
│ │ ├── SubQueryCompiler.cs
│ │ ├── AliasDependencyChecker.cs
│ │ ├── AliasMapper.cs
│ │ ├── SourceExpressionRemover.cs
│ │ ├── ScalarSubQueryRewriter.cs
│ │ ├── SqlValueDeflator.cs
│ │ ├── SqlAggregateChecker.cs
│ │ └── Localizer.cs
│ ├── Common
│ │ ├── SqlUnionizer.cs
│ │ ├── DbFormatter.cs
│ │ ├── MultisetChecker.cs
│ │ ├── HierarchyChecker.cs
│ │ ├── SqlLiftWhereClauses.cs
│ │ ├── NamedColumn.cs
│ │ ├── SqlRetyper.cs
│ │ ├── SqlGatherColumnsProduced.cs
│ │ ├── SqlNodeAnnotation.cs
│ │ ├── SqlCaseSimplifier.cs
│ │ ├── SequenceOfOne.cs
│ │ ├── SqlAliasDependencyChecker.cs
│ │ ├── SqlGatherProducedAliases.cs
│ │ ├── SqlGatherConsumedAliases.cs
│ │ ├── SqlScope.cs
│ │ ├── SqlFlattener.cs
│ │ ├── QueryExtractor.cs
│ │ ├── SqlLiftIndependentRowExpressions.cs
│ │ ├── SqlRewriteScalarSubqueries.cs
│ │ ├── SqlExpander.cs
│ │ ├── Group.cs
│ │ ├── SqlMultiplexer.cs
│ │ ├── OneTimeEnumerable.cs
│ │ ├── SqlReorderer.cs
│ │ ├── SqlSelectionLifter.cs
│ │ ├── LinkOptimizationScope.cs
│ │ ├── SqlRemoveConstantOrderBy.cs
│ │ ├── OrderedResults.cs
│ │ ├── SqlDuplicator.cs
│ │ ├── SqlPredicateLifter.cs
│ │ ├── CompatibilityAnnotation.cs
│ │ ├── SqlGatherReferencedColumns.cs
│ │ ├── SqlNamer.cs
│ │ ├── SqlColumnizer.cs
│ │ ├── SqlDeflator.cs
│ │ ├── QueryInfo.cs
│ │ ├── SqlParameterInfo.cs
│ │ ├── BigJoinChecker.cs
│ │ ├── SqlAliasesReferenced.cs
│ │ ├── CompiledSubQuery.cs
│ │ ├── SqlResolver.cs
│ │ └── ObjectReaderFactory.cs
│ └── Expressions
│ │ ├── KnownExpression.cs
│ │ ├── LinkedTableExpression.cs
│ │ └── InternalExpression.cs
├── Interfaces
│ ├── IFunctionResult.cs
│ ├── IDeferredSourceFactory.cs
│ ├── ISingleResult.cs
│ ├── IDataServices.cs
│ ├── IExecuteResult.cs
│ ├── IMultipleResults.cs
│ └── ICompiledQuery.cs
├── IdentityMangement
│ ├── KeyManager.cs
│ ├── KeyManagerOfTK.cs
│ ├── IdentityCache.cs
│ ├── MultiKey.cs
│ ├── SingleKeyManager.cs
│ └── IdentityManager.cs
├── Mapping
│ ├── ConstantsEnums.cs
│ ├── Accesssors
│ │ ├── Delegates.cs
│ │ ├── LinkDefValueAccessor.cs
│ │ ├── EntityRefDefValueAccessor.cs
│ │ ├── LinkDefSourceAccessor.cs
│ │ ├── EntitySetDefValueAccessor.cs
│ │ ├── EntityRefDefSourceAccessor.cs
│ │ ├── EntitySetDefSourceAccessor.cs
│ │ ├── LinkValueAccessor.cs
│ │ ├── EntityRefValueAccessor.cs
│ │ └── EntitySetValueAccessor.cs
│ ├── SourceState.cs
│ ├── DbmlShared
│ │ ├── ReturnMapping.cs
│ │ ├── TableMapping.cs
│ │ ├── MemberMapping.cs
│ │ └── ParameterMapping.cs
│ ├── MappingSource
│ │ └── AttributeMappingSource.cs
│ ├── AttributedMetaModel
│ │ ├── MethodFinder.cs
│ │ ├── InheritanceBaseFinder.cs
│ │ └── AttributedMetaParameter.cs
│ ├── MappedMetaModel
│ │ ├── MappedReturnParameter.cs
│ │ └── MappedParameter.cs
│ └── MetaModel
│ │ ├── MetaParameter.cs
│ │ └── MetaTable.cs
├── ChangeManagement
│ ├── RelatedItem.cs
│ ├── ChangeConflictSession.cs
│ ├── ReadOnlyChangeTracker.cs
│ ├── ModifiedMemberInfo.cs
│ └── ChangeDirector.cs
├── LinqToSqlExtensions.cs
├── Exceptions
│ ├── ChangeConflictException.cs
│ ├── ForeignKeyReferenceAlreadyHasValueException.cs
│ └── DuplicateKeyException.cs
├── Properties
│ └── AssemblyInfo.cs
├── BindingLists
│ └── BindingList.cs
├── Querying
│ └── SubqueryRules.cs
└── SD.Tools.LinqToSQL2.sln
├── tests
├── SourceProjects
│ ├── log_WriteTests.txt
│ ├── WriteTests.llblgenproj.typeimports
│ └── log_AdventureWorks2008.txt
├── ReadWriteTests
│ ├── packages.config
│ ├── Pair.cs
│ ├── App.config
│ └── Properties
│ │ └── AssemblyInfo.cs
├── AdventureWorks2008Model
│ ├── packages.config
│ ├── App.config
│ └── Properties
│ │ └── AssemblyInfo.cs
├── WriteTestsModel
│ ├── App.config
│ └── Properties
│ │ └── AssemblyInfo.cs
└── GenerateTestCode.cmd
├── NewTypeTests
├── DatabaseFixture.cs
├── NewTypeTests.csproj
└── TypedDataContext.cs
└── README.md
/PATENTS.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/albahari/LinqToSQL2/HEAD/PATENTS.txt
--------------------------------------------------------------------------------
/src/SD.Tools.LinqToDB.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/albahari/LinqToSQL2/HEAD/src/SD.Tools.LinqToDB.snk
--------------------------------------------------------------------------------
/tests/SourceProjects/log_WriteTests.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/albahari/LinqToSQL2/HEAD/tests/SourceProjects/log_WriteTests.txt
--------------------------------------------------------------------------------
/tests/SourceProjects/WriteTests.llblgenproj.typeimports:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/tests/SourceProjects/log_AdventureWorks2008.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/albahari/LinqToSQL2/HEAD/tests/SourceProjects/log_AdventureWorks2008.txt
--------------------------------------------------------------------------------
/tests/ReadWriteTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/tests/AdventureWorks2008Model/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/DbEngines/SqlServer/SqlCEProvider.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.DbEngines.SqlServer
2 | {
3 | internal class SqlCEProvider : Sql2000Provider
4 | {
5 | #warning [FB] REFACTOR Might be removed, CE has been discontinued by MS.
6 | }
7 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/ICompiledSubQuery.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.Interfaces
2 | {
3 | internal interface ICompiledSubQuery {
4 | IExecuteResult Execute(IProvider provider, object[] parentArgs, object[] userArgs);
5 | }
6 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IObjectReaderSession.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.Interfaces
2 | {
3 | internal interface IObjectReaderSession : IConnectionUser, IDisposable {
4 | bool IsBuffered { get; }
5 | void Buffer();
6 | }
7 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IReaderProvider.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.Interfaces
2 | {
3 | internal interface IReaderProvider : IProvider {
4 | IDataServices Services { get; }
5 | IConnectionManager ConnectionManager { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlSource.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal abstract class SqlSource : SqlNode {
6 | internal SqlSource(SqlNodeType nt, Expression sourceExpression)
7 | : base(nt, sourceExpression) {
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IConnectionUser.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.Interfaces
2 | {
3 | ///
4 | /// Interface for objects which use a connection at a given time T, e.g. an active data reader.
5 | ///
6 | internal interface IConnectionUser
7 | {
8 | void CompleteUse();
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlStatement.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal abstract class SqlStatement : SqlNode {
6 | internal SqlStatement(SqlNodeType nodeType, Expression sourceExpression)
7 | : base(nodeType, sourceExpression) {
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/tests/WriteTestsModel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tests/AdventureWorks2008Model/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/ExpectNoAliasRefs.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | internal class ExpectNoAliasRefs : SqlVisitor
6 | {
7 | internal override SqlExpression VisitAliasRef(SqlAliasRef aref)
8 | {
9 | throw Error.UnexpectedNode(aref.NodeType);
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IConnectionManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 | using System.Data.Common;
4 |
5 | namespace System.Data.Linq.Provider.Interfaces
6 | {
7 |
8 | internal interface IConnectionManager
9 | {
10 | DbConnection UseConnection(IConnectionUser user);
11 | void ReleaseConnection(IConnectionUser user);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlUnionizer.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class SqlUnionizer
7 | {
8 | internal static SqlNode Unionize(SqlNode node)
9 | {
10 | return new QueryUnionizer().Visit(node);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlNop.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlNop : SqlSimpleTypeExpression {
7 | internal SqlNop(Type clrType, ProviderType sqlType, Expression sourceExpression)
8 | : base(SqlNodeType.Nop, clrType, sqlType, sourceExpression) {
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/Provider/Common/DbFormatter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Linq.Provider.NodeTypes;
4 | using System.Text;
5 |
6 | namespace System.Data.Linq.Provider.Common {
7 | internal abstract class DbFormatter {
8 | internal abstract string Format(SqlNode node, bool isDebug);
9 | internal abstract string Format(SqlNode node);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Provider/Common/MultisetChecker.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class MultisetChecker
7 | {
8 | internal static bool HasMultiset(SqlExpression expr)
9 | {
10 | MultiSetDetector v = new MultiSetDetector();
11 | v.Visit(expr);
12 | return v.FoundMultiset;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Provider/Common/HierarchyChecker.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class HierarchyChecker
7 | {
8 | internal static bool HasHierarchy(SqlExpression expr)
9 | {
10 | QueryHierarchyFinder v = new QueryHierarchyFinder();
11 | v.Visit(expr);
12 | return v.FoundHierarchy;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IObjectReaderFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Common;
2 |
3 | namespace System.Data.Linq.Provider.Interfaces
4 | {
5 | internal interface IObjectReaderFactory {
6 | IObjectReader Create(DbDataReader reader, bool disposeReader, IReaderProvider provider, object[] parentArgs, object[] userArgs, ICompiledSubQuery[] subQueries);
7 | IObjectReader GetNextResult(IObjectReaderSession session, bool disposeReader);
8 | }
9 | }
--------------------------------------------------------------------------------
/src/Interfaces/IFunctionResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics.CodeAnalysis;
4 |
5 | namespace System.Data.Linq
6 | {
7 | ///
8 | /// Interface providing access to a function return value.
9 | ///
10 | public interface IFunctionResult
11 | {
12 | ///
13 | /// The value.
14 | ///
15 | object ReturnValue { get; }
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/tests/ReadWriteTests/Pair.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace ReadWriteTests.SqlServer
7 | {
8 | public class Pair
9 | {
10 | public Pair()
11 | {
12 | }
13 |
14 | public Pair(T1 v1, T2 v2)
15 | {
16 | this.Value1 = v1;
17 | this.Value2 = v2;
18 | }
19 |
20 | public T1 Value1 { get; set; }
21 | public T2 Value2 { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlLiftWhereClauses.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Common
4 | {
5 |
6 | ///
7 | /// Hoist WHERE clauses as close to the root as possible.
8 | ///
9 | internal class SqlLiftWhereClauses
10 | {
11 | internal static SqlNode Lift(SqlNode node, NodeFactory factory)
12 | {
13 | return new WhereClauseLifter(factory).Visit(node);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Provider/Expressions/KnownExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Expressions
4 | {
5 | internal sealed class KnownExpression : InternalExpression {
6 | SqlNode node;
7 | internal KnownExpression(SqlNode node, Type type)
8 | : base(InternalExpressionType.Known, type) {
9 | this.node = node;
10 | }
11 | internal SqlNode Node {
12 | get { return this.node; }
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Provider/Common/NamedColumn.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.Common
2 | {
3 | internal struct NamedColumn
4 | {
5 | string name;
6 | bool isRequired;
7 | internal NamedColumn(string name, bool isRequired)
8 | {
9 | this.name = name;
10 | this.isRequired = isRequired;
11 | }
12 | internal string Name
13 | {
14 | get { return this.name; }
15 | }
16 | internal bool IsRequired
17 | {
18 | get { return this.isRequired; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IObjectReaderCompiler.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Common;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Interfaces
5 | {
6 | internal interface IObjectReaderCompiler {
7 | IObjectReaderFactory Compile(SqlExpression expression, Type elementType);
8 | IObjectReaderSession CreateSession(DbDataReader reader, IReaderProvider provider, object[] parentArgs, object[] userArgs, ICompiledSubQuery[] subQueries);
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Interfaces/IDeferredSourceFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq.Expressions;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace System.Data.Linq
9 | {
10 | using System.Data.Linq.Mapping;
11 |
12 | internal interface IDeferredSourceFactory
13 | {
14 | IEnumerable CreateDeferredSource(object instance);
15 | IEnumerable CreateDeferredSource(object[] keyValues);
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlRetyper.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class SqlRetyper
7 | {
8 | TypeCorrector visitor;
9 |
10 | internal SqlRetyper(NodeFactory factory)
11 | {
12 | this.visitor = new TypeCorrector(factory);
13 | }
14 |
15 | internal SqlNode Retype(SqlNode node)
16 | {
17 | return this.visitor.Visit(node);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlIncludeScope.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlIncludeScope : SqlNode {
6 | SqlNode child;
7 | internal SqlIncludeScope(SqlNode child, Expression sourceExpression)
8 | : base(SqlNodeType.IncludeScope, sourceExpression) {
9 | this.child = child;
10 | }
11 | internal SqlNode Child {
12 | get {return this.child;}
13 | set {this.child = value;}
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/IdentityMangement/KeyManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Security;
7 | using System.Security.Permissions;
8 | using System.Runtime.CompilerServices;
9 |
10 | namespace System.Data.Linq
11 | {
12 | using System.Data.Linq.Mapping;
13 | using Linq;
14 |
15 | internal abstract class KeyManager
16 | {
17 | internal abstract Type KeyType { get; }
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlGatherColumnsProduced.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | internal class SqlGatherColumnsProduced
8 | {
9 | static internal List GatherColumns(SqlSource source)
10 | {
11 | List columns = new List();
12 | new ProducedColumnsGatherer(columns).Visit(source);
13 | return columns;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlBlock.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlBlock : SqlStatement {
7 | private List statements;
8 |
9 | internal SqlBlock(Expression sourceExpression)
10 | : base(SqlNodeType.Block, sourceExpression) {
11 | this.statements = new List();
12 | }
13 |
14 | internal List Statements {
15 | get { return this.statements; }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/ExpectNoSharedExpressions.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | internal class ExpectNoSharedExpressions : SqlVisitor
6 | {
7 | internal override SqlExpression VisitSharedExpression(SqlSharedExpression shared)
8 | {
9 | throw Error.UnexpectedSharedExpression();
10 | }
11 | internal override SqlExpression VisitSharedExpressionRef(SqlSharedExpressionRef sref)
12 | {
13 | throw Error.UnexpectedSharedExpressionReference();
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/ProducedAliasGatherer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | internal class ProducedAliasGatherer : SqlVisitor
7 | {
8 | private HashSet _produced = new HashSet();
9 |
10 | internal override SqlAlias VisitAlias(SqlAlias a)
11 | {
12 | _produced.Add(a);
13 | return base.VisitAlias(a);
14 | }
15 |
16 | internal HashSet Produced
17 | {
18 | get { return _produced; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlNodeAnnotation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace System.Data.Linq.Provider.Common {
6 |
7 | ///
8 | /// Annotation about a particular SqlNode.
9 | ///
10 | internal abstract class SqlNodeAnnotation {
11 | string message;
12 | internal SqlNodeAnnotation(string message) {
13 | this.message = message;
14 | }
15 | internal string Message {
16 | get {return this.message;}
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlCaseSimplifier.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 |
7 | ///
8 | /// SQL with CASE statements is harder to read. This visitor attempts to reduce CASE
9 | /// statements to equivalent (but easier to read) logic.
10 | ///
11 | internal class SqlCaseSimplifier
12 | {
13 | internal static SqlNode Simplify(SqlNode node, NodeFactory sql)
14 | {
15 | return new CaseSimplifier(sql).Visit(node);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Mapping/ConstantsEnums.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace LinqToSqlShared.Mapping
8 | {
9 | ///
10 | /// DatabaseMapping and related classes represent a parsed version of the
11 | /// XML mapping string. This unvalidated intermediate representation is
12 | /// necessary because unused mappings are intentially never validated.
13 | ///
14 | internal enum MappingParameterDirection
15 | {
16 | In,
17 | Out,
18 | InOut
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Provider/Interfaces/IObjectReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.Data;
6 | using System.Linq.Expressions;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Reflection;
10 | using System.Text;
11 | using System.Globalization;
12 | using System.Data.Linq;
13 |
14 | namespace System.Data.Linq.Provider.Interfaces
15 | {
16 |
17 | internal interface IObjectReader : IEnumerator, IDisposable {
18 | IObjectReaderSession Session { get; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Provider/Common/SequenceOfOne.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class SequenceOfOne : IEnumerable, IEnumerable
7 | {
8 | T[] sequence;
9 | internal SequenceOfOne(T value)
10 | {
11 | this.sequence = new T[] { value };
12 | }
13 | public IEnumerator GetEnumerator()
14 | {
15 | return ((IEnumerable)this.sequence).GetEnumerator();
16 | }
17 |
18 | IEnumerator IEnumerable.GetEnumerator()
19 | {
20 | return this.GetEnumerator();
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlDelete.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlDelete : SqlStatement {
6 | private SqlSelect select;
7 |
8 | internal SqlDelete(SqlSelect select, Expression sourceExpression)
9 | : base(SqlNodeType.Delete, sourceExpression) {
10 | this.Select = select;
11 | }
12 |
13 | internal SqlSelect Select {
14 | get { return this.select; }
15 | set {
16 | if (value == null)
17 | throw Error.ArgumentNull("value");
18 | this.select = value;
19 | }
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Mapping/Accesssors/Delegates.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq.Expressions;
5 | using System.Reflection;
6 | using System.Reflection.Emit;
7 | using System.Security.Permissions;
8 | using System.Security;
9 | using System.Runtime.CompilerServices;
10 |
11 | namespace System.Data.Linq.Mapping
12 | {
13 | using Linq;
14 | using System.Diagnostics.CodeAnalysis;
15 |
16 | internal delegate V DGet(T t);
17 | internal delegate void DSet(T t, V v);
18 | internal delegate void DRSet(ref T t, V v);
19 | }
20 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlAliasDependencyChecker.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | internal static class SqlAliasDependencyChecker
8 | {
9 | internal static bool IsDependent(SqlNode node, HashSet aliasesToCheck, HashSet ignoreExpressions)
10 | {
11 | AliasDependencyChecker v = new AliasDependencyChecker(aliasesToCheck, ignoreExpressions);
12 | v.Visit(node);
13 | return v.hasDependency;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlGatherProducedAliases.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | ///
8 | /// Walk a tree and return the set of unique aliases it produces.
9 | ///
10 | internal class SqlGatherProducedAliases
11 | {
12 | internal static HashSet Gather(SqlNode node)
13 | {
14 | ProducedAliasGatherer g = new ProducedAliasGatherer();
15 | g.Visit(node);
16 | return g.Produced;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlGatherConsumedAliases.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | ///
8 | /// Walk a tree and return the set of unique aliases it consumes.
9 | ///
10 | internal class SqlGatherConsumedAliases
11 | {
12 | internal static HashSet Gather(SqlNode node)
13 | {
14 | ConsumedAliaseGatherer g = new ConsumedAliaseGatherer();
15 | g.Visit(node);
16 | return g.Consumed;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlDiscriminatorOf.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlDiscriminatorOf : SqlSimpleTypeExpression {
7 | SqlExpression obj;
8 | internal SqlDiscriminatorOf(SqlExpression obj, Type clrType, ProviderType sqlType, Expression sourceExpression)
9 | : base(SqlNodeType.DiscriminatorOf, clrType, sqlType, sourceExpression) {
10 | this.obj = obj;
11 | }
12 | internal SqlExpression Object {
13 | get { return this.obj; }
14 | set { this.obj = value; }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/Interfaces/ISingleResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics.CodeAnalysis;
4 |
5 | namespace System.Data.Linq
6 | {
7 | ///
8 | /// An interface for representing the result of a mapped function with a single return sequence.
9 | ///
10 | [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "[....]: Meant to represent a database table which is delayed loaded and doesn't provide collection semantics.")]
11 | public interface ISingleResult : IEnumerable, IFunctionResult, IDisposable { }
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlScope.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Common
4 | {
5 | internal class SqlScope
6 | {
7 | #region Member Declarations
8 | private SqlNode source;
9 | private SqlScope containing;
10 | #endregion
11 |
12 | internal SqlScope(SqlNode source, SqlScope containing)
13 | {
14 | this.source = source;
15 | this.containing = containing;
16 | }
17 | internal SqlNode Source
18 | {
19 | get { return this.source; }
20 | }
21 | internal SqlScope ContainingScope
22 | {
23 | get { return this.containing; }
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Provider/Expressions/LinkedTableExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Expressions
4 | {
5 | internal sealed class LinkedTableExpression : InternalExpression {
6 | private SqlLink link;
7 | private ITable table;
8 | internal LinkedTableExpression(SqlLink link, ITable table, Type type)
9 | : base(InternalExpressionType.LinkedTable, type) {
10 | this.link = link;
11 | this.table = table;
12 | }
13 | internal SqlLink Link {
14 | get {return this.link;}
15 | }
16 | internal ITable Table {
17 | get {return this.table;}
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlVariable.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlVariable : SqlSimpleTypeExpression {
7 | private string name;
8 |
9 | internal SqlVariable(Type clrType, ProviderType sqlType, string name, Expression sourceExpression)
10 | : base(SqlNodeType.Variable, clrType, sqlType, sourceExpression) {
11 | if (name == null)
12 | throw Error.ArgumentNull("name");
13 | this.name = name;
14 | }
15 |
16 | internal string Name {
17 | get { return this.name; }
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlSharedExpressionRef.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlSharedExpressionRef : SqlExpression {
6 | private SqlSharedExpression expr;
7 |
8 | internal SqlSharedExpressionRef(SqlSharedExpression expr)
9 | : base(SqlNodeType.SharedExpressionRef, expr.ClrType, expr.SourceExpression) {
10 | this.expr = expr;
11 | }
12 |
13 | internal SqlSharedExpression SharedExpression {
14 | get { return this.expr; }
15 | }
16 |
17 | internal override ProviderType SqlType {
18 | get { return this.expr.SqlType; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/ChangeManagement/RelatedItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.Linq.Expressions;
6 | using System.Reflection;
7 | using System.Text;
8 | using System.Linq;
9 | using System.Runtime.CompilerServices;
10 |
11 | namespace System.Data.Linq
12 | {
13 | using System.Data.Linq.Mapping;
14 | using Linq;
15 |
16 | internal struct RelatedItem
17 | {
18 | internal MetaType Type;
19 | internal object Item;
20 | internal RelatedItem(MetaType type, object item)
21 | {
22 | this.Type = type;
23 | this.Item = item;
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlClientParameter.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlClientParameter : SqlSimpleTypeExpression {
7 | // Expression>
8 | LambdaExpression accessor;
9 | internal SqlClientParameter(Type clrType, ProviderType sqlType, LambdaExpression accessor, Expression sourceExpression):
10 | base(SqlNodeType.ClientParameter, clrType, sqlType, sourceExpression) {
11 | this.accessor = accessor;
12 | }
13 | internal LambdaExpression Accessor {
14 | get { return this.accessor; }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlFlattener.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | ///
7 | /// Class which flatten object expressions into rows
8 | ///
9 | internal class SqlFlattener
10 | {
11 | ObjectExpressionFlattener visitor;
12 |
13 | internal SqlFlattener(NodeFactory sql, SqlColumnizer columnizer)
14 | {
15 | this.visitor = new ObjectExpressionFlattener(sql, columnizer);
16 | }
17 |
18 | internal SqlNode Flatten(SqlNode node)
19 | {
20 | node = this.visitor.Visit(node);
21 | return node;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/IdentityMangement/KeyManagerOfTK.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Security;
7 | using System.Security.Permissions;
8 | using System.Runtime.CompilerServices;
9 |
10 | namespace System.Data.Linq
11 | {
12 | using System.Data.Linq.Mapping;
13 | using Linq;
14 |
15 | internal abstract class KeyManager : KeyManager
16 | {
17 | internal abstract K CreateKeyFromInstance(T instance);
18 | internal abstract bool TryCreateKeyFromValues(object[] values, out K k);
19 | internal abstract IEqualityComparer Comparer { get; }
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/ExpectRationalizedBooleans.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | ///
6 | /// A validator which enforces rationalized boolean expressions.
7 | ///
8 | internal class ExpectRationalizedBooleans : SqlBooleanMismatchVisitor
9 | {
10 | internal override SqlExpression ConvertValueToPredicate(SqlExpression bitExpression)
11 | {
12 | throw Error.ExpectedPredicateFoundBit();
13 | }
14 |
15 | internal override SqlExpression ConvertPredicateToValue(SqlExpression predicateExpression)
16 | {
17 | throw Error.ExpectedBitFoundPredicate();
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/IdentityMangement/IdentityCache.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Security;
7 | using System.Security.Permissions;
8 | using System.Runtime.CompilerServices;
9 |
10 | namespace System.Data.Linq
11 | {
12 | using System.Data.Linq.Mapping;
13 | using Linq;
14 |
15 | internal abstract class IdentityCache
16 | {
17 | internal abstract object Find(object[] keyValues);
18 | internal abstract object FindLike(object instance);
19 | internal abstract object InsertLookup(object instance);
20 | internal abstract bool RemoveLike(object instance);
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlRow.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlRow : SqlNode {
7 | private List columns;
8 |
9 | internal SqlRow(Expression sourceExpression)
10 | : base(SqlNodeType.Row, sourceExpression) {
11 | this.columns = new List();
12 | }
13 |
14 | internal List Columns {
15 | get { return this.columns; }
16 | }
17 |
18 | internal SqlColumn Find(string name) {
19 | foreach (SqlColumn c in this.columns) {
20 | if (name == c.Name)
21 | return c;
22 | }
23 | return null;
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/Funcletizer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Linq.Expressions;
4 |
5 | namespace System.Data.Linq.Provider.Visitors
6 | {
7 | internal static class Funcletizer
8 | {
9 | ///
10 | /// Expression handler which marks all expressions which solely refer to local elements, so these can be inlined and won't be
11 | /// converted to SQL fragments.
12 | ///
13 | ///
14 | ///
15 | internal static Expression Funcletize(Expression expression)
16 | {
17 | return new Localizer(new LocalMapper().MapLocals(expression)).Localize(expression);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Mapping/SourceState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Linq.Expressions;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Text;
10 | using System.Diagnostics;
11 | using System.Runtime.Serialization;
12 | using System.Diagnostics.CodeAnalysis;
13 | using System.Data.Linq.BindingLists;
14 |
15 | namespace System.Data.Linq {
16 | internal static class SourceState {
17 | internal static readonly IEnumerable Loaded = (IEnumerable)new T[] { };
18 | internal static readonly IEnumerable Assigned = (IEnumerable)new T[] { };
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlDoNotVisitExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlDoNotVisitExpression : SqlExpression {
6 | private SqlExpression expression;
7 |
8 | internal SqlDoNotVisitExpression(SqlExpression expr)
9 | : base(SqlNodeType.DoNotVisit, expr.ClrType, expr.SourceExpression) {
10 | if (expr == null)
11 | throw Error.ArgumentNull("expr");
12 | this.expression = expr;
13 | }
14 |
15 | internal SqlExpression Expression {
16 | get { return this.expression; }
17 | }
18 |
19 | internal override ProviderType SqlType {
20 | get { return this.expression.SqlType; }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/ProducedColumnsGatherer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | internal class ProducedColumnsGatherer : SqlVisitor
7 | {
8 | private List columns;
9 |
10 | internal ProducedColumnsGatherer(List columns)
11 | {
12 | this.columns = columns;
13 | }
14 | internal override SqlSelect VisitSelect(SqlSelect select)
15 | {
16 | foreach(SqlColumn c in @select.Row.Columns)
17 | {
18 | this.columns.Add(c);
19 | }
20 | return @select;
21 | }
22 | internal override SqlNode VisitUnion(SqlUnion su)
23 | {
24 | return su;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Provider/Common/QueryExtractor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | internal class QueryExtractor
8 | {
9 | internal static SqlClientQuery Extract(SqlSubSelect subquery, IEnumerable parentParameters)
10 | {
11 | SqlClientQuery cq = new SqlClientQuery(subquery);
12 | if(parentParameters != null)
13 | {
14 | cq.Parameters.AddRange(parentParameters);
15 | }
16 | SubSelectDuplicator v = new SubSelectDuplicator(cq.Arguments, cq.Parameters);
17 | cq.Query = (SqlSubSelect)v.Visit(subquery);
18 | return cq;
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlLiftIndependentRowExpressions.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 |
7 | ///
8 | /// Find projection expressions on the right side of CROSS APPLY that do not
9 | /// depend exclusively on right side productions and move them outside of the
10 | /// CROSS APPLY by enclosing the CROSS APPLY with a new source.
11 | ///
12 | internal class SqlLiftIndependentRowExpressions
13 | {
14 | internal static SqlNode Lift(SqlNode node)
15 | {
16 | ColumnLifter cl = new ColumnLifter();
17 | node = cl.Visit(node);
18 | return node;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlRewriteScalarSubqueries.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | ///
7 | /// converts correlated scalar subqueries into outer-applies
8 | ///
9 | /// must be run after flattener.
10 | internal class SqlRewriteScalarSubqueries
11 | {
12 | ScalarSubQueryRewriter visitor;
13 |
14 | internal SqlRewriteScalarSubqueries(NodeFactory sqlFactory)
15 | {
16 | this.visitor = new ScalarSubQueryRewriter(sqlFactory);
17 | }
18 |
19 | internal SqlNode Rewrite(SqlNode node)
20 | {
21 | return this.visitor.Visit(node);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/ExpectNoFloatingColumns.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | internal class ExpectNoFloatingColumns : SqlVisitor
6 | {
7 | internal override SqlRow VisitRow(SqlRow row)
8 | {
9 | foreach(SqlColumn c in row.Columns)
10 | {
11 | this.Visit(c.Expression);
12 | }
13 | return row;
14 | }
15 | internal override SqlTable VisitTable(SqlTable tab)
16 | {
17 | foreach(SqlColumn c in tab.Columns)
18 | {
19 | this.Visit(c.Expression);
20 | }
21 | return tab;
22 | }
23 | internal override SqlExpression VisitColumn(SqlColumn col)
24 | {
25 | throw Error.UnexpectedFloatingColumn();
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlExpander.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 |
7 | ///
8 | /// duplicates an expression up until a column or column ref is encountered
9 | /// goes 'deep' through alias ref's
10 | /// assumes that columnizing has been done already
11 | ///
12 | internal class SqlExpander
13 | {
14 | NodeFactory factory;
15 |
16 | internal SqlExpander(NodeFactory factory)
17 | {
18 | this.factory = factory;
19 | }
20 |
21 | internal SqlExpression Expand(SqlExpression exp)
22 | {
23 | return (new ExpressionDuplicator(this.factory)).VisitExpression(exp);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlValue.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlValue : SqlSimpleTypeExpression {
7 | private object value;
8 | private bool isClient;
9 |
10 | internal SqlValue(Type clrType, ProviderType sqlType, object value, bool isClientSpecified, Expression sourceExpression)
11 | : base(SqlNodeType.Value, clrType, sqlType, sourceExpression) {
12 | this.value = value;
13 | this.isClient = isClientSpecified;
14 | }
15 |
16 | internal object Value {
17 | get { return this.value; }
18 | }
19 |
20 | internal bool IsClientSpecified {
21 | get { return this.isClient; }
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlStoredProcedureCall.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Mapping;
3 | using System.Linq.Expressions;
4 |
5 | namespace System.Data.Linq.Provider.NodeTypes
6 | {
7 | internal class SqlStoredProcedureCall : SqlUserQuery {
8 | private MetaFunction function;
9 |
10 | internal SqlStoredProcedureCall(MetaFunction function, SqlExpression projection, IEnumerable args, Expression source)
11 | : base(SqlNodeType.StoredProcedureCall, projection, args, source) {
12 | if (function == null)
13 | throw Error.ArgumentNull("function");
14 | this.function = function;
15 | }
16 |
17 | internal MetaFunction Function {
18 | get { return this.function; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Interfaces/IDataServices.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq.Expressions;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace System.Data.Linq {
9 | using System.Data.Linq.Mapping;
10 |
11 | internal interface IDataServices {
12 | DataContext Context { get; }
13 | MetaModel Model { get; }
14 | IDeferredSourceFactory GetDeferredSourceFactory(MetaDataMember member);
15 | object GetCachedObject(Expression query);
16 | bool IsCachedObject(MetaType type, object instance);
17 | object InsertLookupCachedObject(MetaType type, object instance);
18 | void OnEntityMaterialized(MetaType type, object instance);
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlClientArray.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.Common;
3 | using System.Linq.Expressions;
4 |
5 | namespace System.Data.Linq.Provider.NodeTypes
6 | {
7 | internal class SqlClientArray : SqlSimpleTypeExpression {
8 | private List expressions;
9 |
10 | internal SqlClientArray(Type clrType, ProviderType sqlType, SqlExpression[ ] exprs, Expression sourceExpression)
11 | : base(SqlNodeType.ClientArray, clrType, sqlType, sourceExpression) {
12 | this.expressions = new List();
13 | if (exprs != null)
14 | this.Expressions.AddRange(exprs);
15 | }
16 |
17 | internal List Expressions {
18 | get { return this.expressions; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlRowNumber.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.Common;
3 | using System.Linq.Expressions;
4 |
5 | namespace System.Data.Linq.Provider.NodeTypes
6 | {
7 | internal class SqlRowNumber : SqlSimpleTypeExpression {
8 | private List orderBy;
9 |
10 | internal List OrderBy {
11 | get { return orderBy; }
12 | }
13 |
14 | internal SqlRowNumber(Type clrType, ProviderType sqlType, List orderByList, Expression sourceExpression)
15 | : base(SqlNodeType.RowNumber, clrType, sqlType, sourceExpression) {
16 | if (orderByList == null) {
17 | throw Error.ArgumentNull("orderByList");
18 | }
19 |
20 | this.orderBy = orderByList;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/SubqueryValidator.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | ///
6 | /// Ensure that the subquery follows the rules for subqueries.
7 | ///
8 | internal class SubqueryValidator : Provider.Visitors.ExpressionVisitor
9 | {
10 | bool isTopLevel = true;
11 | internal override Expression VisitMethodCall(MethodCallExpression m)
12 | {
13 | bool was = isTopLevel;
14 | try
15 | {
16 | if(isTopLevel && !SubqueryRules.IsSupportedTopLevelMethod(m.Method))
17 | throw Error.SubqueryDoesNotSupportOperator(m.Method.Name);
18 | isTopLevel = false;
19 | return base.VisitMethodCall(m);
20 | }
21 | finally
22 | {
23 | isTopLevel = was;
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlAlias.cs:
--------------------------------------------------------------------------------
1 | namespace System.Data.Linq.Provider.NodeTypes
2 | {
3 | internal class SqlAlias : SqlSource {
4 | private string name;
5 | private SqlNode node;
6 |
7 | internal SqlAlias(SqlNode node)
8 | : base(SqlNodeType.Alias, node.SourceExpression) {
9 | this.Node = node;
10 | }
11 |
12 | internal string Name {
13 | get { return this.name; }
14 | set { this.name = value; }
15 | }
16 |
17 | internal SqlNode Node {
18 | get { return this.node; }
19 | set {
20 | if (value == null)
21 | throw Error.ArgumentNull("value");
22 | if (!(value is SqlExpression || value is SqlSelect || value is SqlTable || value is SqlUnion))
23 | throw Error.UnexpectedNode(value.NodeType);
24 | this.node = value;
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Provider/Common/Group.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | internal class Group : IGrouping, IEnumerable, IEnumerable
8 | {
9 | #region Member Declarations
10 | private K key;
11 | private IEnumerable items;
12 | #endregion
13 |
14 | internal Group(K key, IEnumerable items)
15 | {
16 | this.key = key;
17 | this.items = items;
18 | }
19 |
20 | K IGrouping.Key
21 | {
22 | get { return this.key; }
23 | }
24 |
25 | IEnumerator IEnumerable.GetEnumerator()
26 | {
27 | return (IEnumerator)this.GetEnumerator();
28 | }
29 |
30 | public IEnumerator GetEnumerator()
31 | {
32 | return this.items.GetEnumerator();
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlMultiplexer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | ///
8 | /// convert multiset & element expressions into separate queries
9 | ///
10 | internal class SqlMultiplexer
11 | {
12 | MultiSetMultiPlexer _multiSetMultiPlexor;
13 |
14 | internal SqlMultiplexer(SqlMultiplexerOptionType options, IEnumerable parentParameters, NodeFactory sqlFactory)
15 | {
16 | this._multiSetMultiPlexor = new MultiSetMultiPlexer(options, parentParameters, sqlFactory);
17 | }
18 |
19 | internal SqlNode Multiplex(SqlNode node)
20 | {
21 | return this._multiSetMultiPlexor.Visit(node);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/ColumnNameGatherer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | internal class ColumnNameGatherer : SqlVisitor
7 | {
8 | public ColumnNameGatherer()
9 | : base()
10 | {
11 | this.Names = new HashSet();
12 | }
13 |
14 | internal override SqlExpression VisitColumn(SqlColumn col)
15 | {
16 | if(!String.IsNullOrEmpty(col.Name))
17 | {
18 | this.Names.Add(col.Name);
19 | }
20 |
21 | return base.VisitColumn(col);
22 | }
23 |
24 | internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
25 | {
26 | Visit(cref.Column);
27 |
28 | return base.VisitColumnRef(cref);
29 | }
30 |
31 | public HashSet Names { get; set; }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/SideEffectChecker.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | ///
6 | /// Visitor which checks whether there's a side effect to be expected when the query is compiled.
7 | ///
8 | internal class SideEffectChecker : SqlVisitor
9 | {
10 | bool hasSideEffect;
11 |
12 | internal bool HasSideEffect(SqlNode node)
13 | {
14 | this.hasSideEffect = false;
15 | this.Visit(node);
16 | return this.hasSideEffect;
17 | }
18 |
19 | internal override SqlExpression VisitJoinedCollection(SqlJoinedCollection jc)
20 | {
21 | this.hasSideEffect = true;
22 | return jc;
23 | }
24 |
25 | internal override SqlExpression VisitClientQuery(SqlClientQuery cq)
26 | {
27 | return cq;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/ExpectNoMethodCalls.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | ///
6 | /// A validator which enforces that no more SqlMethodCall nodes exist in the tree.
7 | ///
8 | internal class ExpectNoMethodCalls : SqlVisitor
9 | {
10 |
11 | internal override SqlExpression VisitMethodCall(SqlMethodCall mc)
12 | {
13 | // eventually we may support this type of stuff given the SQL CLR, but for now it is illegal
14 | throw Error.MethodHasNoSupportConversionToSql(mc.Method.Name);
15 | }
16 |
17 | // check everything except selection expressions (which will be client or ignored)
18 | internal override SqlSelect VisitSelect(SqlSelect select)
19 | {
20 | return this.VisitSelectCore(select);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Provider/Common/OneTimeEnumerable.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class OneTimeEnumerable : IEnumerable, IEnumerable
7 | {
8 | IEnumerator enumerator;
9 |
10 | internal OneTimeEnumerable(IEnumerator enumerator)
11 | {
12 | Diagnostics.Debug.Assert(enumerator != null);
13 | this.enumerator = enumerator;
14 | }
15 |
16 | public IEnumerator GetEnumerator()
17 | {
18 | if(this.enumerator == null)
19 | {
20 | throw Error.CannotEnumerateResultsMoreThanOnce();
21 | }
22 | IEnumerator e = this.enumerator;
23 | this.enumerator = null;
24 | return e;
25 | }
26 |
27 | IEnumerator IEnumerable.GetEnumerator()
28 | {
29 | return this.GetEnumerator();
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlSimpleTypeExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | ///
7 | /// A SqlExpression with a simple implementation of ClrType and SqlType.
8 | ///
9 | internal abstract class SqlSimpleTypeExpression : SqlExpression {
10 | private ProviderType sqlType;
11 |
12 | internal SqlSimpleTypeExpression(SqlNodeType nodeType, Type clrType, ProviderType sqlType, Expression sourceExpression)
13 | : base(nodeType, clrType, sourceExpression) {
14 | this.sqlType = sqlType;
15 | }
16 |
17 | internal override ProviderType SqlType {
18 | get { return this.sqlType; }
19 | }
20 |
21 | internal void SetSqlType(ProviderType type) {
22 | this.sqlType = type;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlMemberAssign.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlMemberAssign : SqlNode {
6 | private MemberInfo member;
7 | private SqlExpression expression;
8 |
9 | internal SqlMemberAssign(MemberInfo member, SqlExpression expr)
10 | : base(SqlNodeType.MemberAssign, expr.SourceExpression) {
11 | if (member == null)
12 | throw Error.ArgumentNull("member");
13 | this.member = member;
14 | this.Expression = expr;
15 | }
16 |
17 | internal MemberInfo Member {
18 | get { return this.member; }
19 | }
20 |
21 | internal SqlExpression Expression {
22 | get { return this.expression; }
23 | set {
24 | if (value == null)
25 | throw Error.ArgumentNull("value");
26 | this.expression = value;
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/LiteralValidator.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | ///
6 | /// A validator that ensures literal values are reasonable.
7 | ///
8 | internal class LiteralValidator : SqlVisitor
9 | {
10 | internal override SqlExpression VisitValue(SqlValue value)
11 | {
12 | if(!value.IsClientSpecified
13 | && value.ClrType.IsClass
14 | && value.ClrType != typeof(string)
15 | && value.ClrType != typeof(Type)
16 | && value.Value != null)
17 | {
18 | throw Error.ClassLiteralsNotAllowed(value.ClrType);
19 | }
20 | return value;
21 | }
22 |
23 | internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
24 | {
25 | bo.Left = this.VisitExpression(bo.Left);
26 | return bo;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Mapping/DbmlShared/ReturnMapping.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.Linq;
5 | using System.Data.Linq.Mapping;
6 | using System.Globalization;
7 |
8 | namespace LinqToSqlShared.Mapping
9 | {
10 | ///
11 | /// DatabaseMapping and related classes represent a parsed version of the
12 | /// XML mapping string. This unvalidated intermediate representation is
13 | /// necessary because unused mappings are intentially never validated.
14 | ///
15 | internal class ReturnMapping
16 | {
17 | #warning [FB] THIS TYPE IS A BIT USELESS, AS IT ONLY WRAPS A STRING VALUE. SEE WHETHER IT'S REALLY NEEDED.
18 | string dbType;
19 |
20 | internal string DbType
21 | {
22 | get { return this.dbType; }
23 | set { this.dbType = value; }
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/Provider/Common/SqlReorderer.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 | using System.Data.Linq.Provider.Visitors;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | ///
7 | /// moves order-by clauses from sub-queries to outer-most or top selects
8 | /// removes ordering in correlated sub-queries
9 | ///
10 | internal class SqlReorderer
11 | {
12 | #region Member Declarations
13 | private TypeSystemProvider typeProvider;
14 | private NodeFactory sql;
15 | #endregion
16 |
17 | internal SqlReorderer(TypeSystemProvider typeProvider, NodeFactory sqlFactory)
18 | {
19 | this.typeProvider = typeProvider;
20 | this.sql = sqlFactory;
21 | }
22 |
23 | internal SqlNode Reorder(SqlNode node)
24 | {
25 | return new OrderByLifter(this.typeProvider, this.sql).Visit(node);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/MultiSetDetector.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.NodeTypes;
2 |
3 | namespace System.Data.Linq.Provider.Visitors
4 | {
5 | internal class MultiSetDetector : SqlVisitor
6 | {
7 | internal bool FoundMultiset { get; set; }
8 |
9 |
10 | internal override SqlExpression VisitMultiset(SqlSubSelect sms)
11 | {
12 | this.FoundMultiset = true;
13 | return sms;
14 | }
15 |
16 | internal override SqlExpression VisitElement(SqlSubSelect elem)
17 | {
18 | return elem;
19 | }
20 |
21 | internal override SqlExpression VisitClientQuery(SqlClientQuery cq)
22 | {
23 | return cq;
24 | }
25 |
26 | internal override SqlExpression VisitExists(SqlSubSelect ss)
27 | {
28 | return ss;
29 | }
30 |
31 | internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
32 | {
33 | return ss;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/Interfaces/IExecuteResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics.CodeAnalysis;
4 |
5 | namespace System.Data.Linq
6 | {
7 | ///
8 | /// The result of executing a query.
9 | ///
10 | public interface IExecuteResult : IDisposable
11 | {
12 | ///
13 | /// The return value or result of the executed query. This object has the same type as the
14 | /// query expression's Type property.
15 | ///
16 | object ReturnValue { get; }
17 |
18 | ///
19 | /// Retrieves the nth output parameter. This method is normally used when the query is a mapped
20 | /// function with output parameters.
21 | ///
22 | ///
23 | ///
24 | object GetParameterValue(int parameterIndex);
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/LinqToSqlExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | #if NET6_0
6 | namespace System.Data.Linq
7 | {
8 | public static class LinqToSqlExtensions
9 | {
10 | // These extension methods make it easier for users to compare dates with datetimes.
11 |
12 | public static DateOnly DateOnly (this DateTime dateTime) => System.DateOnly.FromDateTime (dateTime);
13 | public static DateOnly? DateOnly (this DateTime? dateTime) => dateTime == null ? null : System.DateOnly.FromDateTime (dateTime.Value);
14 |
15 | public static TimeOnly TimeOnly (this DateTime dateTime) => System.TimeOnly.FromDateTime (dateTime);
16 | public static TimeOnly? TimeOnly (this DateTime? dateTime) => dateTime == null ? null : System.TimeOnly.FromDateTime (dateTime.Value);
17 | }
18 | }
19 | #endif
20 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlUpdate.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq.Expressions;
3 |
4 | namespace System.Data.Linq.Provider.NodeTypes
5 | {
6 | internal class SqlUpdate : SqlStatement {
7 | private SqlSelect select;
8 | private List assignments;
9 |
10 | internal SqlUpdate(SqlSelect select, IEnumerable assignments, Expression sourceExpression)
11 | : base(SqlNodeType.Update, sourceExpression) {
12 | this.Select = select;
13 | this.assignments = new List(assignments);
14 | }
15 |
16 | internal SqlSelect Select {
17 | get { return this.select; }
18 | set {
19 | if (value == null)
20 | throw Error.ArgumentNull("value");
21 | this.select = value;
22 | }
23 | }
24 |
25 | internal List Assignments {
26 | get { return this.assignments; }
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Provider/Visitors/ConsumedAliaseGatherer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | internal class ConsumedAliaseGatherer : SqlVisitor
7 | {
8 | private HashSet _consumed = new HashSet();
9 |
10 | internal void VisitAliasConsumed(SqlAlias a)
11 | {
12 | _consumed.Add(a);
13 | }
14 |
15 | internal override SqlExpression VisitColumn(SqlColumn col)
16 | {
17 | VisitAliasConsumed(col.Alias);
18 | VisitExpression(col.Expression);
19 | return col;
20 | }
21 | internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
22 | {
23 | VisitAliasConsumed(cref.Column.Alias);
24 | return cref;
25 | }
26 |
27 | internal HashSet Consumed
28 | {
29 | get { return _consumed; }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/tests/ReadWriteTests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/DbEngines/SqlServer/SqlBooleanizer.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Mapping;
2 | using System.Data.Linq.Provider.Common;
3 | using System.Data.Linq.Provider.NodeTypes;
4 | using System.Data.Linq.Provider.Visitors;
5 |
6 | namespace System.Data.Linq.DbEngines.SqlServer {
7 |
8 | ///
9 | /// Locate cases in which there is a 'Bit' but a 'Predicate' is expected or vice-versa.
10 | /// Transform these expressions into expressions of the expected type.
11 | ///
12 | internal class SqlBooleanizer {
13 | ///
14 | /// Rationalize boolean expressions for the given node.
15 | ///
16 | internal static SqlNode Rationalize(SqlNode node, TypeSystemProvider typeProvider, MetaModel model) {
17 | return new Booleanizer(new SqlFactory(typeProvider, model)).Visit(node);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/SqlSupersetValidator.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | ///
7 | /// Validates the integrity of super-SQL trees.
8 | ///
9 | internal class SqlSupersetValidator
10 | {
11 |
12 | List validators = new List();
13 |
14 | ///
15 | /// Add a validator to the collection of validators to run.
16 | ///
17 | internal void AddValidator(SqlVisitor validator)
18 | {
19 | this.validators.Add(validator);
20 | }
21 |
22 | ///
23 | /// Execute each current validator.
24 | ///
25 | internal void Validate(SqlNode node)
26 | {
27 | foreach(SqlVisitor validator in this.validators)
28 | {
29 | validator.Visit(node);
30 | }
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/tests/WriteTestsModel/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | [assembly: AssemblyTitle("")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: AssemblyConfiguration("")]
7 | [assembly: AssemblyCompany("")]
8 | [assembly: AssemblyProduct("")]
9 | [assembly: AssemblyCopyright("")]
10 | [assembly: AssemblyTrademark("")]
11 | [assembly: AssemblyCulture("")]
12 |
13 | // Version information for an assembly consists of the following four values:
14 | //
15 | // Major Version
16 | // Minor Version
17 | // Build Number
18 | // Revision
19 | //
20 | // You can specify all the values or you can default the Build and Revision Numbers
21 | // by using the '*' as shown below:
22 | // [assembly: AssemblyVersion("1.0.*")]
23 | [assembly: AssemblyVersion("1.0.0.0")]
24 | [assembly: AssemblyFileVersion("1.0.0.0")]
25 |
--------------------------------------------------------------------------------
/src/Interfaces/IMultipleResults.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics.CodeAnalysis;
4 |
5 | namespace System.Data.Linq {
6 |
7 | ///
8 | /// An interface for representing results of mapped functions or queries with variable return sequences.
9 | ///
10 | public interface IMultipleResults : IFunctionResult, IDisposable {
11 | ///
12 | /// Retrieves the next result as a sequence of Type 'TElement'.
13 | ///
14 | ///
15 | ///
16 | [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "[....]: Generic parameters are required for strong-typing of the return type.")]
17 | IEnumerable GetResult();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Provider/Visitors/ColumnTypeValidator.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Visitors
5 | {
6 | ///
7 | /// Column ClrType must agree with the expression that it points to.
8 | ///
9 | internal class ColumnTypeValidator : SqlVisitor
10 | {
11 |
12 | internal override SqlRow VisitRow(SqlRow row)
13 | {
14 | for(int i = 0, n = row.Columns.Count; i < n; i++)
15 | {
16 | SqlColumn col = row.Columns[i];
17 | SqlExpression expr = this.VisitExpression(col.Expression);
18 | if(expr != null)
19 | {
20 | if(TypeSystem.GetNonNullableType(col.ClrType) != TypeSystem.GetNonNullableType(expr.ClrType))
21 | {
22 | throw Error.ColumnClrTypeDoesNotAgreeWithExpressionsClrType();
23 | }
24 | }
25 | }
26 | return row;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Provider/Common/SqlSelectionLifter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 | using System.Data.Linq.Provider.Visitors;
4 |
5 | namespace System.Data.Linq.Provider.Common
6 | {
7 | internal static class SqlSelectionLifter
8 | {
9 | internal static bool CanLift(SqlSource source, HashSet aliasesForLifting, HashSet liftedExpressions)
10 | {
11 | SelectionLifter v = new SelectionLifter(false, aliasesForLifting, liftedExpressions);
12 | v.VisitSource(source);
13 | return v.CanLiftAll;
14 | }
15 |
16 | internal static List> Lift(SqlSource source, HashSet aliasesForLifting, HashSet liftedExpressions)
17 | {
18 | SelectionLifter v = new SelectionLifter(true, aliasesForLifting, liftedExpressions);
19 | v.VisitSource(source);
20 | return v.Lifted;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/tests/GenerateTestCode.cmd:
--------------------------------------------------------------------------------
1 | @Echo off
2 |
3 | Echo ================================================================
4 | Echo Generating code: Read test model, AdventureWorks2008, C#
5 | Echo ================================================================
6 | "C:\users\frans\LLBLGen Pro v4.2\cligenerator.exe" "SourceProjects\AdventureWorks2008.llblgenproj" "ReadTestsAdventureWorks2008" "C#" ".NET 4.5" "General" "SD.LinqToSql" "AdventureWorks2008Model" 0 "SourceProjects\log_AdventureWorks2008.txt"
7 | Echo ================================================================
8 | Echo Generating code: Write test model, WriteTests, C#
9 | Echo ================================================================
10 | "C:\users\frans\LLBLGen Pro v4.2\cligenerator.exe" "SourceProjects\WriteTests.llblgenproj" "WriteTests" "C#" ".NET 4.5" "General" "SD.LinqToSql" "WriteTestsModel" 0 "SourceProjects\log_WriteTests.txt"
11 |
--------------------------------------------------------------------------------
/src/Exceptions/ChangeConflictException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Linq;
4 | using System.Linq;
5 | using System.Diagnostics.CodeAnalysis;
6 |
7 | namespace System.Data.Linq {
8 | ///
9 | /// DLinq-specific custom exception factory.
10 | ///
11 | [SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable", Justification = "Unknown reason.")]
12 | [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "Unknown reason.")]
13 | public class ChangeConflictException : Exception {
14 | public ChangeConflictException() { }
15 | public ChangeConflictException(string message) : base(message) { }
16 | public ChangeConflictException(string message, Exception innerException) : base(message, innerException) { }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Provider/NodeTypes/SqlSubSelect.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Linq.Provider.Common;
2 |
3 | namespace System.Data.Linq.Provider.NodeTypes
4 | {
5 | internal class SqlSubSelect : SqlSimpleTypeExpression {
6 | private SqlSelect select;
7 |
8 | internal SqlSubSelect(SqlNodeType nt , Type clrType, ProviderType sqlType , SqlSelect select)
9 | : base(nt, clrType, sqlType, select.SourceExpression) {
10 | switch (nt) {
11 | case SqlNodeType.Multiset:
12 | case SqlNodeType.ScalarSubSelect:
13 | case SqlNodeType.Element:
14 | case SqlNodeType.Exists:
15 | break;
16 | default:
17 | throw Error.UnexpectedNode(nt);
18 | }
19 | this.Select = select;
20 | }
21 |
22 | internal SqlSelect Select {
23 | get { return this.select; }
24 | set {
25 | if (value == null)
26 | throw Error.ArgumentNull("value");
27 | this.select = value;
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Provider/Common/LinkOptimizationScope.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Linq.Provider.NodeTypes;
3 |
4 | namespace System.Data.Linq.Provider.Common
5 | {
6 | internal class LinkOptimizationScope
7 | {
8 | Dictionary