Entities with complex properties

Jan 31, 2016 at 8:11 PM
Edited Jan 31, 2016 at 8:13 PM

It seems that entity types that contain complex properties are not working. For example, if I modify your tests so that Airport class contains one complex property, test fails and throws InvalidCastException (Unable to cast object of type 'System.Data.Entity.Core.Mapping.ComplexPropertyMapping' to type 'System.Data.Entity.Core.Mapping.ScalarPropertyMapping').

I studied the code and it is obvious why it is failing but I don't know how to fix it. I would love to use your code to enable TVFs with Entity Framework but this is major issue for me. Any ideas how to fix it?


    public class MyComplexProperty
        public string Data1 { get; set; }
        public int Data2 { get; set; }

    public class Airport
        public string IATACode { get; set; }
        public string CityCode { get; set; }
        public string CountryCode { get; set; }
        public string Name { get; set; }
        public byte TerminalCount { get; set; }
        public AirportType Type { get; set; }

        public MyComplexProperty Complex { get; set; }

Feb 3, 2016 at 6:20 AM
Without a stack trace I speculate that the bug is in the FindStoreTypeUsages function in this code:
var propertyMapping =
    (ScalarPropertyMapping)entityTypeMapping.Fragments.SelectMany(f => f.PropertyMappings)
    .FirstOrDefault(p => p.Property == property);
Instead of assuming that we are always dealing with a scalar property it should check if it is not a complex property mapping and if it is it should drill down to primitive properties.

Feb 3, 2016 at 6:22 AM
I created a bug to track that - https://codefirstfunctions.codeplex.com/workitem/16. Not sure when I will be able to tackle this.