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

Nested complex type case not handled properly #60

Open kavhad opened 6 years ago

kavhad commented 6 years ago

In a case where a complex type is a subproperty within a complex type, then running EnumToLookup.GenerateMigrationSql(...) seems to ignore the enum property. The following code describes the case

public class Entity {
   public int Id {get;set;}
   public Foo MyFoo {get;set;}
}

[ComplexType]
public class Foo {
   public string Text {get;set;}
   public Bar MyBar {get;set;}
}

[ComplexType]
public class Bar {
   public string Text {get; get;}
   public BarType Type {get;set;}
}

public enum BarType {
   SMALL,
   MEDIUM, 
   LARGE
}
kavhad commented 6 years ago

I noticed these comment lines in the file MetaDatahandler.cs:

// Note that complex types can't be nested (ref http://stackoverflow.com/a/20332503/10245 ) // so it's safe to not recurse even though the data model suggests you should have to.

So this is by design, but there's no such limitation at least not in EF version 6.1.3, nested complex types are valid and works like expected. The limitation is with relational properties within complex types.

timabell commented 6 years ago

Would you be able to write a unit test & fix? Then do a PR? Or if not I could do it on a consultancy basis. Is it causing you a problem with your code/business?

kavhad commented 6 years ago

I'll try to do a fix for it myself and do a PR.

Thanks for everything you've put into it already.

timabell commented 6 years ago

Cool. You're welcome!