@@ -60,6 +60,9 @@ public static PropertyInfo GetPrimaryKeyPropertyInfo(this Type entityType)
6060 if ( entityType == null )
6161 throw new ArgumentNullException ( nameof ( entityType ) ) ;
6262
63+ if ( InMemoryCache . Instance . PrimaryKeyMapping . ContainsKey ( entityType ) )
64+ return InMemoryCache . Instance . PrimaryKeyMapping [ entityType ] ;
65+
6366 var propertyInfo = entityType
6467 . GetRuntimeProperties ( )
6568 . Where ( x => x . IsMapped ( ) )
@@ -74,6 +77,8 @@ public static PropertyInfo GetPrimaryKeyPropertyInfo(this Type entityType)
7477
7578 if ( propertyInfo != null && propertyInfo . IsMapped ( ) )
7679 {
80+ InMemoryCache . Instance . PrimaryKeyMapping [ entityType ] = propertyInfo ;
81+
7782 return propertyInfo ;
7883 }
7984 }
@@ -97,11 +102,16 @@ public static PropertyInfo GetPrimaryKeyPropertyInfo<T>()
97102 /// <returns>The name of the table.</returns>
98103 public static string GetTableName ( this Type entityType )
99104 {
105+ if ( InMemoryCache . Instance . TableNameMapping . ContainsKey ( entityType ) )
106+ return InMemoryCache . Instance . TableNameMapping [ entityType ] ;
107+
100108 var tableName = entityType . GetTypeInfo ( ) . GetCustomAttribute < TableAttribute > ( ) ? . Name ;
101109
102110 if ( string . IsNullOrEmpty ( tableName ) )
103111 tableName = PluralizationHelper . Pluralize ( entityType . Name ) ;
104112
113+ InMemoryCache . Instance . TableNameMapping [ entityType ] = tableName ;
114+
105115 return tableName ;
106116 }
107117
@@ -145,6 +155,11 @@ public static int GetColumnOrder(this PropertyInfo pi)
145155 /// <returns>The name of the foreign key.</returns>
146156 public static PropertyInfo GetForeignKeyPropertyInfo ( this Type sourceType , Type foreignType )
147157 {
158+ var tupleKey = Tuple . Create ( sourceType , foreignType ) ;
159+
160+ if ( InMemoryCache . Instance . ForeignKeyMapping . ContainsKey ( tupleKey ) )
161+ return InMemoryCache . Instance . ForeignKeyMapping [ tupleKey ] ;
162+
148163 var properties = sourceType . GetRuntimeProperties ( ) . Where ( x => x . IsMapped ( ) ) ;
149164 var foreignPropertyInfo = properties . SingleOrDefault ( x => x . PropertyType == foreignType ) ;
150165
@@ -179,6 +194,8 @@ public static PropertyInfo GetForeignKeyPropertyInfo(this Type sourceType, Type
179194 }
180195 }
181196
197+ InMemoryCache . Instance . ForeignKeyMapping [ tupleKey ] = propertyInfo ;
198+
182199 return propertyInfo ;
183200 }
184201
0 commit comments