timabell / ef-enum-to-lookup

Generates lookup tables from enum references in Microsoft Entity Framework 6.1
https://www.nuget.org/packages/ef-enum-to-lookup
69 stars 29 forks source link

Enums in child types not recognized in TPH mapping #39

Open prodibaugh opened 9 years ago

prodibaugh commented 9 years ago

Enum properties in subclasses are not recognized when TPH mapping is utilized. This seems to be due to the fact that the FindSchemaMappingFragment in MetadataHander returns null when a child entity type is encountered. I will change to TPT mapping strategy as a workaround.

public abstract class Furniture
{
    public int Id { get; set; }
    public Pattern Pattern { get; set; }
}

public class Bed : Furniture
{
    public MattressType Mattress { get; set; }
}

[Flags]
public enum MattressType
{
    Soft = 1,
    Firm = 2
}

[Test]
    public void FindsReferences_InChildEntityType_TPHMappingStrategy()
    {
        IList<EnumReference> references;
        using (var context = new MagicContext())
        {
            references = _enumToLookup.FindEnumReferences(context);
        }
        var mattress = references.Count(r => r.EnumType == typeof(MattressType));
        Assert.AreEqual(1, mattress, "Wrong number of Mattress refs found");
    }
samitdesai commented 8 years ago

Is this bug fixed or still open. i run the above example and test fails.

timabell commented 8 years ago

Still open.

samitdesai commented 8 years ago

HI i am new to EF sorry if it don't make sense. But is there any workaround to this.

timabell commented 8 years ago

I haven't looked into it, couldn't say.