1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Data . Entity . Core . Metadata . Edm ;
4
4
using System . Data . Entity . Core . Objects ;
@@ -11,10 +11,9 @@ namespace RefactorThis.GraphDiff.Internal
11
11
internal static class Extensions
12
12
{
13
13
internal static IEnumerable < PropertyInfo > GetPrimaryKeyFieldsFor ( this IObjectContextAdapter context , Type entityType )
14
- {
14
+ {
15
15
var metadata = context . ObjectContext . MetadataWorkspace
16
- . GetItems < EntityType > ( DataSpace . OSpace )
17
- . SingleOrDefault ( p => p . FullName == entityType . FullName ) ;
16
+ . GetEntityTypeByType ( entityType ) ;
18
17
19
18
if ( metadata == null )
20
19
{
@@ -32,10 +31,8 @@ internal static IEnumerable<NavigationProperty> GetRequiredNavigationPropertiesF
32
31
33
32
internal static IEnumerable < NavigationProperty > GetNavigationPropertiesForType ( this IObjectContextAdapter context , Type entityType )
34
33
{
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 ;
39
36
}
40
37
41
38
internal static string GetEntitySetName ( this IObjectContextAdapter context , Type entityType )
@@ -55,5 +52,25 @@ internal static string GetEntitySetName(this IObjectContextAdapter context, Type
55
52
56
53
return set != null ? set . Name : null ;
57
54
}
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
+ }
58
75
}
59
76
}
0 commit comments