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

Add support for nested complex types (#60) #61

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
559 changes: 305 additions & 254 deletions EfEnumToLookup/LookupGenerator/MetadataHandler.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions EfEnumToLookupTests/Db/MagicContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class MagicContext : DbContext
// Table-per-Type (TPT)
public DbSet<Vehicle> Vehicles { get; set; }

// Nested enum in complex type
public DbSet<CandyBag> CandyBags { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Fox>().Map(f => f.ToTable("Foxies"));
Expand Down
214 changes: 110 additions & 104 deletions EfEnumToLookupTests/EfEnumToLookupTests.csproj
Original file line number Diff line number Diff line change
@@ -1,111 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Owner

@timabell timabell Oct 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why's the whole file changed? line-endings or something?

<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>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DED8AB21-6D20-43F6-B9A7-522D63F34423}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EfEnumToLookupTests</RootNamespace>
<AssemblyName>EfEnumToLookupTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>EfEnumToLookup.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\Category.cs" />
<Compile Include="Model\Fur.cs" />
<Compile Include="Model\Pedigree.cs" />
<Compile Include="Model\Truck.cs" />
<Compile Include="Model\Car.cs" />
<Compile Include="Model\Vehicle.cs" />
<Compile Include="Model\Bed.cs" />
<Compile Include="Model\Chair.cs" />
<Compile Include="Model\Furniture.cs" />
<Compile Include="Model\Aspirations.cs" />
<Compile Include="Model\Cave.cs" />
<Compile Include="Db\MagicContext.cs" />
<Compile Include="Model\Constants.cs" />
<Compile Include="Model\Echo.cs" />
<Compile Include="Model\Eon.cs" />
<Compile Include="Model\Geology.cs" />
<Compile Include="Model\Heat.cs" />
<Compile Include="Model\Importance.cs" />
<Compile Include="Model\Pattern.cs" />
<Compile Include="Model\Relation.cs" />
<Compile Include="Model\Warren.cs" />
<Compile Include="Model\Chicken.cs" />
<Compile Include="Model\Ears.cs" />
<Compile Include="Model\Fox.cs" />
<Compile Include="Model\Legs.cs" />
<Compile Include="Model\Rabbit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Db\TestInitializer.cs" />
<Compile Include="Tests\EnumParserTests.cs" />
<Compile Include="Tests\ModelParsingTests.cs" />
<Compile Include="Tests\TestConfiguration.cs" />
<Compile Include="Tests\TestStuff.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="EfEnumToLookup.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EfEnumToLookup\EfEnumToLookup.csproj">
<Project>{E6D4F1FB-D017-4BE2-AD13-90153BF479B1}</Project>
<Name>EfEnumToLookup</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<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>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DED8AB21-6D20-43F6-B9A7-522D63F34423}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EfEnumToLookupTests</RootNamespace>
<AssemblyName>EfEnumToLookupTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>EfEnumToLookup.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\Category.cs" />
<Compile Include="Model\Fur.cs" />
<Compile Include="Model\JellyBean.cs" />
<Compile Include="Model\CandyBag.cs" />
<Compile Include="Model\CandySize.cs" />
<Compile Include="Model\Pedigree.cs" />
<Compile Include="Model\CandyLook.cs" />
<Compile Include="Model\Lollipop.cs" />
<Compile Include="Model\ThreeChoicesOfLollipops.cs" />
<Compile Include="Model\Truck.cs" />
<Compile Include="Model\Car.cs" />
<Compile Include="Model\Vehicle.cs" />
<Compile Include="Model\Bed.cs" />
<Compile Include="Model\Chair.cs" />
<Compile Include="Model\Furniture.cs" />
<Compile Include="Model\Aspirations.cs" />
<Compile Include="Model\Cave.cs" />
<Compile Include="Db\MagicContext.cs" />
<Compile Include="Model\Constants.cs" />
<Compile Include="Model\Echo.cs" />
<Compile Include="Model\Eon.cs" />
<Compile Include="Model\Geology.cs" />
<Compile Include="Model\Heat.cs" />
<Compile Include="Model\Importance.cs" />
<Compile Include="Model\Pattern.cs" />
<Compile Include="Model\Relation.cs" />
<Compile Include="Model\Warren.cs" />
<Compile Include="Model\Chicken.cs" />
<Compile Include="Model\Ears.cs" />
<Compile Include="Model\Fox.cs" />
<Compile Include="Model\Legs.cs" />
<Compile Include="Model\Rabbit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Db\TestInitializer.cs" />
<Compile Include="Tests\EnumParserTests.cs" />
<Compile Include="Tests\ModelParsingTests.cs" />
<Compile Include="Tests\TestConfiguration.cs" />
<Compile Include="Tests\TestStuff.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="EfEnumToLookup.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EfEnumToLookup\EfEnumToLookup.csproj">
<Project>{E6D4F1FB-D017-4BE2-AD13-90153BF479B1}</Project>
<Name>EfEnumToLookup</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
-->
-->
</Project>
12 changes: 12 additions & 0 deletions EfEnumToLookupTests/Model/CandyBag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations.Schema;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good choice of test names 👍 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was between a candy bag or perhaps an engine with parts, but candy won :)


namespace EfEnumToLookupTests.Model
{
[Table(nameof(CandyBag))]
public class CandyBag
{
public int Id { get; set; }
public ThreeChoicesOfLollipops Lollipops { get; set; }
public JellyBean Jellybeans { get; set; }
}
}
11 changes: 11 additions & 0 deletions EfEnumToLookupTests/Model/CandyLook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace EfEnumToLookupTests.Model
{
[ComplexType]
public class CandyLook
{
public string Shape { get; set; }
public CandySize Size { get; set; }
}
}
15 changes: 15 additions & 0 deletions EfEnumToLookupTests/Model/CandySize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EfEnumToLookupTests.Model
{
public enum CandySize
{
SMALL = 1,
MEDIUM,
LARGE
}
}
11 changes: 11 additions & 0 deletions EfEnumToLookupTests/Model/JellyBean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace EfEnumToLookupTests.Model
{
[ComplexType]
public class JellyBean
{
public int Count { get; set; }
public CandyLook Look { get; set; }
}
}
11 changes: 11 additions & 0 deletions EfEnumToLookupTests/Model/Lollipop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace EfEnumToLookupTests.Model
{
[ComplexType]
public class Lollipop
{
public int Length { get; set; }
public CandyLook Look { get; set; }
}
}
14 changes: 14 additions & 0 deletions EfEnumToLookupTests/Model/ThreeChoicesOfLollipops.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace EfEnumToLookupTests.Model
{
[ComplexType]
public class ThreeChoicesOfLollipops
{
public Lollipop Lollipop1 { get; set; }

public Lollipop Lollipop2 { get; set; }

public Lollipop Lollipop3 { get; set; }
}
}
8 changes: 6 additions & 2 deletions EfEnumToLookupTests/Tests/ModelParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public void FindsReferences()
var eons = references.Count(r => r.EnumType == typeof(Eon));
Assert.AreEqual(2, eons, "Wrong number of Eon refs found");
Assert.IsTrue(references.All(r => r.EnumType.IsEnum), "Non-enum type found");
Assert.AreEqual(13, references.Count);
}
Assert.AreEqual(17, references.Count);

var candySizes = references.Count(r => r.EnumType == typeof(CandySize));
Assert.AreEqual(4, candySizes);

}

[Test]
public void FindsEnumOnType()
Expand Down
20 changes: 20 additions & 0 deletions ExampleUsage/EnumExample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using EfEnumToLookup.LookupGenerator;
using NUnit.Framework;
Expand Down Expand Up @@ -64,6 +65,8 @@ public void ExampleOfGeneratingSql()
public class MyDbContext : DbContext
{
public DbSet<Foo> Foos { get; set; }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unintentional blank lines?


}

/// <summary>
Expand All @@ -74,8 +77,25 @@ public class Foo
public int Id { get; set; }
public Size Size { get; set; }
public Shape Shape { get; set; }

public Bar Bar { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation mismatch?
check out the editorconfig in the root folder

}

[ComplexType]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks off here too

public class Bar
{
public string Name { get; set; }
public Tail Tail { get; set; }
}

[ComplexType]
public class Tail
{
public Size Size { get; set; }
public Shape Shape { get; set; }
}


/// <summary>
/// Example enum that will be converted into a lookup table.
/// </summary>
Expand Down