public override LambdaExpression CreateMaterializer(IEntityType entityType, SelectExpression selectExpression, Func <IProperty, SelectExpression, int> projectionAdder,
                                                            out Dictionary <Type, int[]> typeIndexMap)
        {
            if (selectExpression == null)
            {
                throw new ArgumentNullException(nameof(selectExpression));
            }

            RelationalQueryCompilationContext queryCompilationContext =
                _getQueryCompilationContext(selectExpression);
            var isWithNoLock = queryCompilationContext.QueryAnnotations.OfType <WithNoLockResultOperator>().Any();

            if (isWithNoLock)
            {
                IEnumerable <TableExpression> tableExpressions = selectExpression.Tables.OfType <TableExpression>().ToArray();
                foreach (TableExpression tableExpression in tableExpressions)
                {
                    WithNoLockTableExpression withNoLockTableExpression =
                        new WithNoLockTableExpression(tableExpression.Table, tableExpression.Schema,
                                                      tableExpression.Alias, tableExpression.QuerySource);
                    selectExpression.RemoveTable(tableExpression);
                    selectExpression.AddTable(withNoLockTableExpression);
                }
            }


            return(base.CreateMaterializer(entityType, selectExpression, projectionAdder, out typeIndexMap));
        }
Beispiel #2
0
        public override Expression VisitSelect(SelectExpression selectExpression)
        {
            RelationalQueryCompilationContext queryCompilationContext = _getQueryCompilationContext(selectExpression);
            var isWithNoLock = queryCompilationContext?.QueryAnnotations?.OfType <WithNoLockResultOperator>().Any();

            if (isWithNoLock.HasValue && isWithNoLock.Value)
            {
                IEnumerable <TableExpression> tableExpressions = selectExpression.Tables.OfType <TableExpression>().ToArray();
                foreach (TableExpression tableExpression in tableExpressions)
                {
                    WithNoLockTableExpression withNoLockTableExpression =
                        new WithNoLockTableExpression(tableExpression.Table, tableExpression.Schema,
                                                      tableExpression.Alias, tableExpression.QuerySource);
                    selectExpression.RemoveTable(tableExpression);
                    selectExpression.AddTable(withNoLockTableExpression);
                }
            }

            return(base.VisitSelect(selectExpression));
        }
Beispiel #3
0
 private bool Equals(WithNoLockTableExpression other)
 => string.Equals(Table, other.Table) &&
 string.Equals(Schema, other.Schema) &&
 string.Equals(Alias, other.Alias) &&
 Equals(QuerySource, other.QuerySource);