neisbut / EntityFramework.MemoryJoin

Extension for EntityFramework for joins to in-memory data
MIT License
56 stars 24 forks source link

Error when List type contains fields (instead of just properties) #4

Closed cjmairair closed 5 years ago

cjmairair commented 5 years ago

Try it and you'll get an error from Entity Framework.

The fix should be in MappingHelper.cs >>GetEntityMapping:

Like this:

        foreach (var member in typeof(T).GetProperties().Cast<MemberInfo>().Concat(typeof(T).GetFields()))
        {
            var memberType = (member is PropertyInfo) ? ((PropertyInfo)member).PropertyType : ((FieldInfo)member).FieldType;

            var baseType = Nullable.GetUnderlyingType(memberType) ?? memberType;
            if (!allowedPropertyMapping.TryGetValue(baseType, out var allowedMappedProps))
                throw new NotSupportedException("Not supported property type");

            var mapProperty = allowedMappedProps.FirstOrDefault(x => allowedProperties.Contains(x));
            if (mapProperty == null)
                throw new NotSupportedException("Too complex object");

            Expression inExp = Expression.MakeMemberAccess(inParam, member);
            if (mapProperty.PropertyType != memberType)
                inExp = Expression.Convert(inExp, mapProperty.PropertyType);

            inMappingPairs.Add(new Tuple<MemberInfo, Expression>(mapProperty, inExp));
neisbut commented 5 years ago

Hi @cjmairair, thanks a lot for a suggested fix! I will address this soon and be back to you.

neisbut commented 5 years ago

@cjmairair, done. Please check 0.5.5 release for this change.

cjmairair commented 5 years ago

Great. Thanks.