Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TPH model discovery problem. Potentially, closes #33, closes #53,… #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
1,021 changes: 1,021 additions & 0 deletions EntityFramework.Utilities/.vs/config/applicationhost.config

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions EntityFramework.Utilities/EntityFramework.Utilities/App.config
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>

<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -11,6 +11,7 @@
<AssemblyName>EntityFramework.Utilities</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -20,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -28,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,19 @@ public EfMapping(DbContext db)
return GetClrTypeFromTypeMapping(metadata, objectItemCollection, m.TypeMapping as EntityTypeMapping);
};


if (mapping.EntityTypeMappings.Any(m => m.IsHierarchyMapping))
{
var withConditions = mapping.EntityTypeMappings.Where(m => m.Fragments[0].Conditions.Any()).ToList();
tableMapping.TPHConfiguration = new TPHConfiguration
{
ColumnName = withConditions.First().Fragments[0].Conditions[0].Column.Name,
Mappings = new Dictionary<Type, string>()
};

if (withConditions.Count > 0)
{
tableMapping.TPHConfiguration = new TPHConfiguration
{
ColumnName = withConditions.First().Fragments[0].Conditions[0].Column.Name,
Mappings = new Dictionary<Type, string>()
};
}
foreach (var item in withConditions)
{
tableMapping.TPHConfiguration.Mappings.Add(
Expand Down
24 changes: 24 additions & 0 deletions EntityFramework.Utilities/Tests/EfMappingFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using EntityFramework.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tests.FakeDomain;

namespace Tests
{

[TestClass]
public class EfMappingFactoryTests
{
[TestMethod]

public void ShouldGetMappingsForContext()
{
var ctx = Context.Sql();
var m = EfMappingFactory.GetMappingsForContext(ctx);
Assert.IsNotNull(m);
}
}
}
1 change: 1 addition & 0 deletions EntityFramework.Utilities/Tests/FakeDomain/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private Context(string connectionString)
public DbSet<PhoneNumber> PhoneNumbers { get; set; }
public DbSet<Email> Emails { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<ApprovedComment> ApprovedComments { get; set; }
public DbSet<NumericTestObject> NumericTestsObjects { get; set; }
public DbSet<MultiPKObject> MultiPKObjects { get; set; }

Expand Down
10 changes: 10 additions & 0 deletions EntityFramework.Utilities/Tests/Models/Comment.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;

namespace Tests.FakeDomain.Models
{
[Table("Comment")]
public class Comment
{
[Key]
public int Id { get; set; }
public string Text { get; set; }
public int PostId { get; set; }
public BlogPost Post { get; set; }
}

[Table("ApprovedComment")]
public class ApprovedComment:Comment
{
public DateTime ApprovedOn { get; set; }
}
}
1 change: 1 addition & 0 deletions EntityFramework.Utilities/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="ConnectionStringReader.cs" />
<Compile Include="ConnectionStrings.cs" />
<Compile Include="AttachAndModifyTest.cs" />
<Compile Include="EfMappingFactoryTests.cs" />
<Compile Include="Models\MultiPKObject.cs" />
<Compile Include="Models\NumericTestObject.cs" />
<Compile Include="UpdateBulkTests.cs" />
Expand Down