1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Data . Entity . Core . Metadata . Edm ;
44using System . Data . Entity . Core . Objects ;
@@ -11,10 +11,9 @@ namespace RefactorThis.GraphDiff.Internal
1111 internal static class Extensions
1212 {
1313 internal static IEnumerable < PropertyInfo > GetPrimaryKeyFieldsFor ( this IObjectContextAdapter context , Type entityType )
14- {
14+ {
1515 var metadata = context . ObjectContext . MetadataWorkspace
16- . GetItems < EntityType > ( DataSpace . OSpace )
17- . SingleOrDefault ( p => p . FullName == entityType . FullName ) ;
16+ . GetEntityTypeByType ( entityType ) ;
1817
1918 if ( metadata == null )
2019 {
@@ -32,10 +31,8 @@ internal static IEnumerable<NavigationProperty> GetRequiredNavigationPropertiesF
3231
3332 internal static IEnumerable < NavigationProperty > GetNavigationPropertiesForType ( this IObjectContextAdapter context , Type entityType )
3433 {
35- return context . ObjectContext . MetadataWorkspace
36- . GetItems < EntityType > ( DataSpace . OSpace )
37- . Single ( p => p . FullName == entityType . FullName )
38- . NavigationProperties ;
34+
35+ return context . ObjectContext . MetadataWorkspace . GetEntityTypeByType ( entityType ) . NavigationProperties ;
3936 }
4037
4138 internal static string GetEntitySetName ( this IObjectContextAdapter context , Type entityType )
@@ -55,5 +52,25 @@ internal static string GetEntitySetName(this IObjectContextAdapter context, Type
5552
5653 return set != null ? set . Name : null ;
5754 }
55+
56+ /// <summary>A MetadataWorkspace extension method that gets entity type by type.</summary>
57+ /// <param name="metadataWorkspace">The metadataWorkspace to act on.</param>
58+ /// <param name="entityType">Type of the entity.</param>
59+ /// <returns>The entity type by type.</returns>
60+ /// not support class in generic class
61+ internal static EntityType GetEntityTypeByType ( this MetadataWorkspace metadataWorkspace , Type entityType )
62+ {
63+ string name = entityType . FullName . Replace ( "+" , "." ) ;
64+ var lenght = name . IndexOf ( "`" ) ;
65+
66+ if ( lenght != - 1 )
67+ {
68+ name = name . Substring ( 0 , lenght ) ;
69+ }
70+
71+ return metadataWorkspace
72+ . GetItems < EntityType > ( DataSpace . OSpace )
73+ . SingleOrDefault ( p => p . FullName == name ) ;
74+ }
5875 }
5976}
0 commit comments