Skip to content

Commit 9831036

Browse files
Merge pull request #170 from Lempireqc/master
for have the good class with MetadataWorkspace
2 parents 284fc97 + a013a5c commit 9831036

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

GraphDiff/GraphDiff.sln

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.12
4+
VisualStudioVersion = 15.0.27130.2003
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphDiff.Tests", "GraphDiff.Tests\GraphDiff.Tests.csproj", "{36762487-8275-440B-8E19-AADA325652E4}"
77
EndProject
@@ -14,8 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3AB2ED
1414
.nuget\NuGet.targets = .nuget\NuGet.targets
1515
EndProjectSection
1616
EndProject
17-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z.Lab", "Z.Lab\Z.Lab.csproj", "{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}"
18-
EndProject
1917
Global
2018
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2119
Debug|Any CPU = Debug|Any CPU
@@ -30,10 +28,6 @@ Global
3028
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
3129
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
3230
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Release|Any CPU.Build.0 = Release|Any CPU
33-
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34-
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
35-
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
36-
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Release|Any CPU.Build.0 = Release|Any CPU
3731
EndGlobalSection
3832
GlobalSection(SolutionProperties) = preSolution
3933
HideSolutionNode = FALSE

GraphDiff/GraphDiff/GraphDiff.csproj

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -33,7 +33,7 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<PropertyGroup>
36-
<SignAssembly>true</SignAssembly>
36+
<SignAssembly>false</SignAssembly>
3737
</PropertyGroup>
3838
<PropertyGroup>
3939
<AssemblyOriginatorKeyFile>zzzproject.pfx</AssemblyOriginatorKeyFile>
@@ -72,16 +72,15 @@
7272
</ItemGroup>
7373
<ItemGroup>
7474
<None Include="packages.config" />
75-
<None Include="zzzproject.pfx" />
7675
</ItemGroup>
7776
<ItemGroup />
7877
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7978
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
80-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
81-
Other similar extension points exist, see Microsoft.Common.targets.
82-
<Target Name="BeforeBuild">
83-
</Target>
84-
<Target Name="AfterBuild">
85-
</Target>
79+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
80+
Other similar extension points exist, see Microsoft.Common.targets.
81+
<Target Name="BeforeBuild">
82+
</Target>
83+
<Target Name="AfterBuild">
84+
</Target>
8685
-->
87-
</Project>
86+
</Project>

GraphDiff/GraphDiff/Internal/Extensions.cs

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Data.Entity.Core.Metadata.Edm;
44
using 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
}

GraphDiff/GraphDiff/Internal/Graph/GraphNode.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Data.Entity;
44
using System.Data.Entity.Core;
@@ -214,7 +214,7 @@ private static void EnsureConcurrency<T>(IObjectContextAdapter db, T entity1, T
214214
var entityType = ObjectContext.GetObjectType(entity1.GetType());
215215
var metadata = db.ObjectContext.MetadataWorkspace;
216216

217-
var objType = metadata.GetItems<EntityType>(DataSpace.OSpace).Single(p => p.FullName == entityType.FullName);
217+
var objType = metadata.GetEntityTypeByType(entityType);
218218

219219
// need internal string, code smells bad.. any better way to do this?
220220
var cTypeName = (string)objType.GetType()

GraphDiff/GraphDiff/Internal/GraphDiffer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RefactorThis.GraphDiff.Internal.Graph;
1+
using RefactorThis.GraphDiff.Internal.Graph;
22
using System;
33
using System.Collections.Generic;
44
using System.Data.Entity;
@@ -100,4 +100,4 @@ private static Expression CreateEqualsExpression(object entity, PropertyInfo key
100100
return Expression.Equal(Expression.Property(parameter, keyProperty), Expression.Constant(keyProperty.GetValue(entity, null), keyProperty.PropertyType));
101101
}
102102
}
103-
}
103+
}

0 commit comments

Comments
 (0)