22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44
5- using System ;
6- using System . Collections . Generic ;
7- using System . Linq ;
85using System . Linq . Expressions ;
96using System . Reflection ;
10- using System . Threading ;
11- using System . Threading . Tasks ;
127using JetBrains . Annotations ;
138using Xtensive . Core ;
149using Xtensive . Orm . FullTextSearchCondition . Interfaces ;
1510using Xtensive . Orm . FullTextSearchCondition . Nodes ;
1611using Xtensive . Orm . Internals ;
17- using Xtensive . Orm . Internals . Prefetch ;
1812using Xtensive . Orm . Linq ;
1913using Xtensive . Reflection ;
2014using Tuple = Xtensive . Tuples . Tuple ;
@@ -51,7 +45,13 @@ public bool Equals(QueryEndpoint other) =>
5145
5246 public override int GetHashCode ( ) => HashCode . Combine ( Provider , RootBuilder ) ;
5347
54- /// <summary>
48+ private static class Traits < T >
49+ {
50+ public static readonly MethodCallExpression RootCallExpression =
51+ Expression . Call ( null , WellKnownMembers . Query . All . MakeGenericMethod ( typeof ( T ) ) ) ;
52+ }
53+
54+ /// <summary>
5555 /// The "starting point" for any LINQ query -
5656 /// a <see cref="IQueryable{T}"/> enumerating all the instances
5757 /// of type <typeparamref name="T"/>.
@@ -61,11 +61,10 @@ public bool Equals(QueryEndpoint other) =>
6161 /// An <see cref="IQueryable{T}"/> enumerating all the instances
6262 /// of type <typeparamref name="T"/>.
6363 /// </returns>
64- public IQueryable < T > All < T > ( )
65- where T : class , IEntity
66- {
67- return Provider . CreateQuery < T > ( BuildRootExpression ( typeof ( T ) ) ) ;
68- }
64+ public IQueryable < T > All < T > ( ) where T : class , IEntity =>
65+ Provider . CreateQuery < T > ( RootBuilder != null
66+ ? RootBuilder . BuildRootExpression ( typeof ( T ) )
67+ : Traits < T > . RootCallExpression ) ;
6968
7069 /// <summary>
7170 /// The "starting point" for dynamic LINQ query -
@@ -77,10 +76,11 @@ public IQueryable<T> All<T>()
7776 /// An <see cref="IQueryable"/> enumerating all the instances
7877 /// of type <paramref name="elementType"/>.
7978 /// </returns>
80- public IQueryable All ( Type elementType )
81- {
82- return ( ( IQueryProvider ) Provider ) . CreateQuery ( BuildRootExpression ( elementType ) ) ;
83- }
79+ public IQueryable All ( Type elementType ) =>
80+ ( ( IQueryProvider ) Provider ) . CreateQuery ( RootBuilder != null
81+ ? RootBuilder . BuildRootExpression ( elementType )
82+ : QueryHelper . CreateEntityQuery ( elementType )
83+ ) ;
8484
8585 #region Full-text related
8686
@@ -970,13 +970,6 @@ private Key GetKeyByValues<T>(ReadOnlySpan<object> keyValues)
970970 return Key . Create ( session . Domain , session . StorageNodeId , session . Domain . Model . Types [ typeof ( T ) ] , TypeReferenceAccuracy . BaseType , keyValues ) ;
971971 }
972972
973- private Expression BuildRootExpression ( Type elementType )
974- {
975- return RootBuilder != null
976- ? RootBuilder . BuildRootExpression ( elementType )
977- : Session . Domain . RootCallExpressionsCache . GetOrAdd ( elementType , ( t ) => Expression . Call ( null , WellKnownMembers . Query . All . MakeGenericMethod ( t ) ) ) ;
978- }
979-
980973 private static void ThrowKeyNotFoundException ( Key key ) =>
981974 throw new KeyNotFoundException ( String . Format ( Strings . EntityWithKeyXDoesNotExist , key ) ) ;
982975
@@ -987,7 +980,6 @@ private static void ThrowKeyNotFoundException(Key key) =>
987980
988981 internal QueryEndpoint ( QueryProvider provider )
989982 {
990- ArgumentNullException . ThrowIfNull ( provider ) ;
991983 Provider = provider ;
992984 }
993985
0 commit comments