@@ -241,17 +241,15 @@ internal static string GenerateSql(DbCommandTree tree, out List<DbParameter> par
241241 commandType = CommandType . Text ;
242242
243243 //Handle Query
244- var queryCommandTree = tree as DbQueryCommandTree ;
245- if ( queryCommandTree != null )
244+ if ( tree is DbQueryCommandTree queryCommandTree )
246245 {
247246 var sqlGen = new SqlGenerator ( ) ;
248247 parameters = null ;
249248 return sqlGen . GenerateSql ( ( DbQueryCommandTree ) tree ) ;
250249 }
251250
252251 //Handle Function
253- var DbFunctionCommandTree = tree as DbFunctionCommandTree ;
254- if ( DbFunctionCommandTree != null )
252+ if ( tree is DbFunctionCommandTree DbFunctionCommandTree )
255253 {
256254 var sqlGen = new SqlGenerator ( ) ;
257255 parameters = null ;
@@ -262,22 +260,19 @@ internal static string GenerateSql(DbCommandTree tree, out List<DbParameter> par
262260 }
263261
264262 //Handle Insert
265- var insertCommandTree = tree as DbInsertCommandTree ;
266- if ( insertCommandTree != null )
263+ if ( tree is DbInsertCommandTree insertCommandTree )
267264 {
268265 return DmlSqlGenerator . GenerateInsertSql ( insertCommandTree , out parameters ) ;
269266 }
270267
271268 //Handle Delete
272- var deleteCommandTree = tree as DbDeleteCommandTree ;
273- if ( deleteCommandTree != null )
269+ if ( tree is DbDeleteCommandTree deleteCommandTree )
274270 {
275271 return DmlSqlGenerator . GenerateDeleteSql ( deleteCommandTree , out parameters ) ;
276272 }
277273
278274 //Handle Update
279- var updateCommandTree = tree as DbUpdateCommandTree ;
280- if ( updateCommandTree != null )
275+ if ( tree is DbUpdateCommandTree updateCommandTree )
281276 {
282277 return DmlSqlGenerator . GenerateUpdateSql ( updateCommandTree , out parameters ) ;
283278 }
@@ -1291,26 +1286,22 @@ public override ISqlFragment Visit(DbNewInstanceExpression e)
12911286 public override ISqlFragment Visit ( DbNotExpression e )
12921287 {
12931288 // Flatten Not(Not(x)) to x.
1294- var notExpression = e . Argument as DbNotExpression ;
1295- if ( notExpression != null )
1289+ if ( e . Argument is DbNotExpression notExpression )
12961290 {
12971291 return notExpression . Argument . Accept ( this ) ;
12981292 }
12991293
1300- var isEmptyExpression = e . Argument as DbIsEmptyExpression ;
1301- if ( isEmptyExpression != null )
1294+ if ( e . Argument is DbIsEmptyExpression isEmptyExpression )
13021295 {
13031296 return VisitIsEmptyExpression ( isEmptyExpression , true ) ;
13041297 }
13051298
1306- var isNullExpression = e . Argument as DbIsNullExpression ;
1307- if ( isNullExpression != null )
1299+ if ( e . Argument is DbIsNullExpression isNullExpression )
13081300 {
13091301 return VisitIsNullExpression ( isNullExpression , true ) ;
13101302 }
13111303
1312- var comparisonExpression = e . Argument as DbComparisonExpression ;
1313- if ( comparisonExpression != null )
1304+ if ( e . Argument is DbComparisonExpression comparisonExpression )
13141305 {
13151306 if ( comparisonExpression . ExpressionKind == DbExpressionKind . Equals )
13161307 {
@@ -1413,8 +1404,7 @@ public override ISqlFragment Visit(DbProjectExpression e)
14131404 // so we have to check it here.
14141405 // We call VisitNewInstanceExpression instead of Visit(DbNewInstanceExpression), since
14151406 // the latter throws.
1416- var newInstanceExpression = e . Projection as DbNewInstanceExpression ;
1417- if ( newInstanceExpression != null )
1407+ if ( e . Projection is DbNewInstanceExpression newInstanceExpression )
14181408 {
14191409 result . Select . Append ( VisitNewInstanceExpression ( newInstanceExpression ) ) ;
14201410 }
@@ -1460,15 +1450,13 @@ public override ISqlFragment Visit(DbPropertyExpression e)
14601450
14611451 // Since the DbVariableReferenceExpression is a proper child of ours, we can reset
14621452 // isVarSingle.
1463- var DbVariableReferenceExpression = e . Instance as DbVariableReferenceExpression ;
1464- if ( DbVariableReferenceExpression != null )
1453+ if ( e . Instance is DbVariableReferenceExpression DbVariableReferenceExpression )
14651454 {
14661455 _isVarRefSingle = false ;
14671456 }
14681457
14691458 // We need to flatten, and have not yet seen the first nested SELECT statement.
1470- var joinSymbol = instanceSql as JoinSymbol ;
1471- if ( joinSymbol != null )
1459+ if ( instanceSql is JoinSymbol joinSymbol )
14721460 {
14731461 varName = GetShortenedName ( varName ) ;
14741462 Debug . Assert ( joinSymbol . NameToExtent . ContainsKey ( varName ) ) ;
@@ -1483,12 +1471,10 @@ public override ISqlFragment Visit(DbPropertyExpression e)
14831471 }
14841472 // ---------------------------------------
14851473 // We have seen the first nested SELECT statement, but not the column.
1486- var symbolPair = instanceSql as SymbolPair ;
1487- if ( symbolPair != null )
1474+ if ( instanceSql is SymbolPair symbolPair )
14881475 {
14891476 varName = GetShortenedName ( varName ) ;
1490- var columnJoinSymbol = symbolPair . Column as JoinSymbol ;
1491- if ( columnJoinSymbol != null )
1477+ if ( symbolPair . Column is JoinSymbol columnJoinSymbol )
14921478 {
14931479 Debug . Assert ( columnJoinSymbol . NameToExtent . ContainsKey ( varName ) ) ;
14941480 symbolPair . Column = columnJoinSymbol . NameToExtent [ varName ] ;
@@ -1728,9 +1714,8 @@ public override ISqlFragment Visit(DbInExpression e)
17281714 SqlBuilder VisitAggregate ( DbAggregate aggregate , object aggregateArgument )
17291715 {
17301716 var aggregateResult = new SqlBuilder ( ) ;
1731- var functionAggregate = aggregate as DbFunctionAggregate ;
17321717
1733- if ( functionAggregate == null )
1718+ if ( ! ( aggregate is DbFunctionAggregate functionAggregate ) )
17341719 {
17351720 throw new NotSupportedException ( ) ;
17361721 }
@@ -2119,8 +2104,7 @@ void ProcessJoinInputResult(ISqlFragment fromExtentFragment, SqlSelectStatement
21192104 // The child has its own select statement, and is not reusing
21202105 // our select statement.
21212106 // This should look a lot like VisitInputExpression().
2122- var sqlSelectStatement = fromExtentFragment as SqlSelectStatement ;
2123- if ( sqlSelectStatement != null )
2107+ if ( fromExtentFragment is SqlSelectStatement sqlSelectStatement )
21242108 {
21252109 if ( sqlSelectStatement . Select . IsEmpty )
21262110 {
@@ -2144,8 +2128,7 @@ void ProcessJoinInputResult(ISqlFragment fromExtentFragment, SqlSelectStatement
21442128 // clone the join symbol, so that we "reuse" the
21452129 // join symbol. Normally, we create a new symbol - see the next block
21462130 // of code.
2147- var oldJoinSymbol = sqlSelectStatement . FromExtents [ 0 ] as JoinSymbol ;
2148- if ( oldJoinSymbol != null )
2131+ if ( sqlSelectStatement . FromExtents [ 0 ] is JoinSymbol oldJoinSymbol )
21492132 {
21502133 // Note: sqlSelectStatement.FromExtents will not do, since it might
21512134 // just be an alias of joinSymbol, and we want an actual JoinSymbol.
@@ -2227,9 +2210,8 @@ void ProcessJoinInputResult(ISqlFragment fromExtentFragment, SqlSelectStatement
22272210 ISqlFragment VisitNewInstanceExpression ( DbNewInstanceExpression e )
22282211 {
22292212 var result = new SqlBuilder ( ) ;
2230- var rowType = e . ResultType . EdmType as RowType ;
22312213
2232- if ( null != rowType )
2214+ if ( e . ResultType . EdmType is RowType rowType )
22332215 {
22342216 var members = rowType . Properties ;
22352217 var separator = string . Empty ;
@@ -2798,8 +2780,7 @@ private static ISqlFragment HandleCanonicalFunctionTruncate(SqlGenerator sqlgen,
27982780 void AddColumns ( SqlSelectStatement selectStatement , Symbol symbol ,
27992781 List < Symbol > columnList , Dictionary < string , Symbol > columnDictionary , ref string separator )
28002782 {
2801- var joinSymbol = symbol as JoinSymbol ;
2802- if ( joinSymbol != null )
2783+ if ( symbol is JoinSymbol joinSymbol )
28032784 {
28042785 if ( ! joinSymbol . IsNestedJoin )
28052786 {
@@ -3103,8 +3084,7 @@ SqlSelectStatement CreateNewSelectStatement(SqlSelectStatement oldStatement,
31033084 // clone the join symbol, so that we "reuse" the
31043085 // join symbol. Normally, we create a new symbol - see the next block
31053086 // of code.
3106- var oldJoinSymbol = oldStatement . FromExtents [ 0 ] as JoinSymbol ;
3107- if ( oldJoinSymbol != null )
3087+ if ( oldStatement . FromExtents [ 0 ] is JoinSymbol oldJoinSymbol )
31083088 {
31093089 // Note: oldStatement.FromExtents will not do, since it might
31103090 // just be an alias of joinSymbol, and we want an actual JoinSymbol.
@@ -3680,13 +3660,11 @@ static bool NeedsInnerQuery(IList<DbAggregate> aggregates)
36803660 /// <returns></returns>
36813661 static bool IsPropertyOverVarRef ( DbExpression expression )
36823662 {
3683- var propertyExpression = expression as DbPropertyExpression ;
3684- if ( propertyExpression == null )
3663+ if ( ! ( expression is DbPropertyExpression propertyExpression ) )
36853664 {
36863665 return false ;
36873666 }
3688- var varRefExpression = propertyExpression . Instance as DbVariableReferenceExpression ;
3689- if ( varRefExpression == null )
3667+ if ( ! ( propertyExpression . Instance is DbVariableReferenceExpression varRefExpression ) )
36903668 {
36913669 return false ;
36923670 }
0 commit comments