44
55using System ;
66using System . Collections . Generic ;
7- using System . Data . Common ;
87using System . Linq ;
98using System . Reflection ;
109using Xtensive . Core ;
1110using Xtensive . Orm . Linq ;
12- using Xtensive . Orm . Model ;
1311using Xtensive . Orm . Providers ;
1412using Xtensive . Orm . Services ;
15- using Xtensive . Sql . Model ;
1613using Xtensive . Sql ;
1714using Xtensive . Sql . Dml ;
1815using QueryParameterBinding = Xtensive . Orm . Services . QueryParameterBinding ;
@@ -24,21 +21,24 @@ internal abstract class Operation<T>
2421 where T : class , IEntity
2522 {
2623 private static readonly MethodInfo TranslateQueryMethod = typeof ( QueryBuilder ) . GetMethod ( "TranslateQuery" ) ;
24+
2725 public readonly QueryProvider QueryProvider ;
26+ public readonly QueryBuilder QueryBuilder ;
2827 public List < QueryParameterBinding > Bindings ;
29- protected DomainHandler DomainHandler ;
30- protected PrimaryIndexMapping [ ] PrimaryIndexes ;
31- public QueryBuilder QueryBuilder ;
32- public Session Session ;
33- protected TypeInfo TypeInfo ;
3428 public SqlTableRef JoinedTableRef ;
3529
30+ protected readonly DomainHandler DomainHandler ;
31+ protected readonly PrimaryIndexMapping [ ] PrimaryIndexes ;
32+ protected readonly TypeInfo TypeInfo ;
33+
34+ public Session Session { get { return QueryBuilder . Session ; } }
35+
3636 public int Execute ( )
3737 {
3838 EnsureTransactionIsStarted ( ) ;
39- QueryProvider . Session . SaveChanges ( ) ;
39+ Session . SaveChanges ( ) ;
4040 int value = ExecuteInternal ( ) ;
41- SessionStateAccessor accessor = DirectStateAccessor . Get ( QueryProvider . Session ) ;
41+ var accessor = DirectStateAccessor . Get ( Session ) ;
4242 accessor . Invalidate ( ) ;
4343 return value ;
4444 }
@@ -49,45 +49,36 @@ protected void EnsureTransactionIsStarted()
4949 {
5050 var accessor = QueryProvider . Session . Services . Demand < DirectSqlAccessor > ( ) ;
5151#pragma warning disable 168
52- DbTransaction notUsed = accessor . Transaction ;
52+ var notUsed = accessor . Transaction ;
5353#pragma warning restore 168
5454 }
5555
5656 protected abstract int ExecuteInternal ( ) ;
5757
58- public QueryTranslationResult GetRequest ( IQueryable < T > query )
59- {
60- return QueryBuilder . TranslateQuery ( query ) ;
61- }
58+ public QueryTranslationResult GetRequest ( IQueryable < T > query ) => QueryBuilder . TranslateQuery ( query ) ;
6259
63- public QueryTranslationResult GetRequest ( Type type , IQueryable query )
64- {
65- return
66- ( QueryTranslationResult ) TranslateQueryMethod . MakeGenericMethod ( type ) . Invoke ( QueryBuilder , new object [ ] { query } ) ;
67- }
60+ public QueryTranslationResult GetRequest ( Type type , IQueryable query ) =>
61+ ( QueryTranslationResult ) TranslateQueryMethod . MakeGenericMethod ( type ) . Invoke ( QueryBuilder , new object [ ] { query } ) ;
6862
69- public TypeInfo GetTypeInfo ( Type entityType )
70- {
71- return Session . Domain . Model . Hierarchies . SelectMany ( a => a . Types ) . Single ( a => a . UnderlyingType == entityType ) ;
72- }
63+ public TypeInfo GetTypeInfo ( Type entityType ) =>
64+ Session . Domain . Model . Hierarchies . SelectMany ( a => a . Types ) . Single ( a => a . UnderlyingType == entityType ) ;
7365
7466 #endregion
7567
7668 protected Operation ( QueryProvider queryProvider )
7769 {
7870 QueryProvider = queryProvider ;
79- Type entityType = typeof ( T ) ;
80- Session = queryProvider . Session ;
81- DomainHandler = Session . Domain . Services . Get < DomainHandler > ( ) ;
82- TypeInfo =
83- queryProvider . Session . Domain . Model . Hierarchies . SelectMany ( a => a . Types ) . Single (
84- a => a . UnderlyingType == entityType ) ;
85- var mapping = Session . StorageNode . Mapping ;
71+ var entityType = typeof ( T ) ;
72+ var session = queryProvider . Session ;
73+ DomainHandler = session . Domain . Services . Get < DomainHandler > ( ) ;
74+ TypeInfo = DomainHandler . Domain . Model . Hierarchies . SelectMany ( a => a . Types )
75+ . Single ( a => a . UnderlyingType == entityType ) ;
76+ var mapping = session . StorageNode . Mapping ;
8677 PrimaryIndexes = TypeInfo . AffectedIndexes
8778 . Where ( i => i . IsPrimary )
8879 . Select ( i => new PrimaryIndexMapping ( i , mapping [ i . ReflectedType ] ) )
8980 . ToArray ( ) ;
90- QueryBuilder = Session . Services . Get < QueryBuilder > ( ) ;
81+ QueryBuilder = session . Services . Get < QueryBuilder > ( ) ;
9182 }
9283
9384 protected QueryCommand ToCommand ( SqlStatement statement )
0 commit comments