Skip to content

Commit

Permalink
Merge pull request #170 from Lempireqc/master
Browse files Browse the repository at this point in the history
for have the good class with MetadataWorkspace
  • Loading branch information
JonathanMagnan authored Dec 13, 2017
2 parents 284fc97 + a013a5c commit 9831036
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
10 changes: 2 additions & 8 deletions GraphDiff/GraphDiff.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
VisualStudioVersion = 15.0.27130.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphDiff.Tests", "GraphDiff.Tests\GraphDiff.Tests.csproj", "{36762487-8275-440B-8E19-AADA325652E4}"
EndProject
Expand All @@ -14,8 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3AB2ED
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z.Lab", "Z.Lab\Z.Lab.csproj", "{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,10 +28,6 @@ Global
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9725B00-669C-409D-9AB8-C674710C8E5D}.Release|Any CPU.Build.0 = Release|Any CPU
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB103C62-0A60-4DB7-BFA8-E9BEFA047DA3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 9 additions & 10 deletions GraphDiff/GraphDiff/GraphDiff.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -33,7 +33,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>zzzproject.pfx</AssemblyOriginatorKeyFile>
Expand Down Expand Up @@ -72,16 +72,15 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="zzzproject.pfx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
33 changes: 25 additions & 8 deletions GraphDiff/GraphDiff/Internal/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Core.Objects;
Expand All @@ -11,10 +11,9 @@ namespace RefactorThis.GraphDiff.Internal
internal static class Extensions
{
internal static IEnumerable<PropertyInfo> GetPrimaryKeyFieldsFor(this IObjectContextAdapter context, Type entityType)
{
{
var metadata = context.ObjectContext.MetadataWorkspace
.GetItems<EntityType>(DataSpace.OSpace)
.SingleOrDefault(p => p.FullName == entityType.FullName);
.GetEntityTypeByType(entityType);

if (metadata == null)
{
Expand All @@ -32,10 +31,8 @@ internal static IEnumerable<NavigationProperty> GetRequiredNavigationPropertiesF

internal static IEnumerable<NavigationProperty> GetNavigationPropertiesForType(this IObjectContextAdapter context, Type entityType)
{
return context.ObjectContext.MetadataWorkspace
.GetItems<EntityType>(DataSpace.OSpace)
.Single(p => p.FullName == entityType.FullName)
.NavigationProperties;

return context.ObjectContext.MetadataWorkspace.GetEntityTypeByType(entityType).NavigationProperties;
}

internal static string GetEntitySetName(this IObjectContextAdapter context, Type entityType)
Expand All @@ -55,5 +52,25 @@ internal static string GetEntitySetName(this IObjectContextAdapter context, Type

return set != null ? set.Name : null;
}

/// <summary>A MetadataWorkspace extension method that gets entity type by type.</summary>
/// <param name="metadataWorkspace">The metadataWorkspace to act on.</param>
/// <param name="entityType">Type of the entity.</param>
/// <returns>The entity type by type.</returns>
/// not support class in generic class
internal static EntityType GetEntityTypeByType(this MetadataWorkspace metadataWorkspace, Type entityType)
{
string name = entityType.FullName.Replace("+", ".");
var lenght = name.IndexOf("`");

if (lenght != -1)
{
name = name.Substring(0, lenght);
}

return metadataWorkspace
.GetItems<EntityType>(DataSpace.OSpace)
.SingleOrDefault(p => p.FullName == name);
}
}
}
4 changes: 2 additions & 2 deletions GraphDiff/GraphDiff/Internal/Graph/GraphNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Core;
Expand Down Expand Up @@ -214,7 +214,7 @@ private static void EnsureConcurrency<T>(IObjectContextAdapter db, T entity1, T
var entityType = ObjectContext.GetObjectType(entity1.GetType());
var metadata = db.ObjectContext.MetadataWorkspace;

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

// need internal string, code smells bad.. any better way to do this?
var cTypeName = (string)objType.GetType()
Expand Down
4 changes: 2 additions & 2 deletions GraphDiff/GraphDiff/Internal/GraphDiffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RefactorThis.GraphDiff.Internal.Graph;
using RefactorThis.GraphDiff.Internal.Graph;
using System;
using System.Collections.Generic;
using System.Data.Entity;
Expand Down Expand Up @@ -100,4 +100,4 @@ private static Expression CreateEqualsExpression(object entity, PropertyInfo key
return Expression.Equal(Expression.Property(parameter, keyProperty), Expression.Constant(keyProperty.GetValue(entity, null), keyProperty.PropertyType));
}
}
}
}

0 comments on commit 9831036

Please sign in to comment.