public object GetValue(int i) { if (_enumerator.Current == null) { return(null); } try { object value; try { value = _currentEntityTypeSelectors[i](_enumerator.Current); #if NET45 var dbgeo = value as DbGeography; if (dbgeo != null) { return(Provider.GetSqlGeography(dbgeo.WellKnownValue.WellKnownText, dbgeo.CoordinateSystemId)); } var dbgeom = value as DbGeometry; if (dbgeom != null) { return(Provider.GetSqlGeometry(dbgeom.WellKnownValue.WellKnownText, dbgeom.CoordinateSystemId)); } #endif } catch (KeyNotFoundException) { // current index is not present in given object type. i.e this column is for some sibling return(null); } // todo - option: copy referenced objects - if it improves performance if (Cols[i].IsNavigationProperty) { return(value); //return 0; //var prop = Cols[i].Type.GetProperty(Cols[i].TableMapping.Pk.Prop); var type = Cols[i].Type; PropertyInfo prop = GetReferenceEntityIdProperty(type, Provider); //var prop = type.GetProperty(tableMapping.Pks.FirstOrDefault().PropertyName); //var prop = type.GetProperty(propertyName); var idValue = prop.GetValue(value); return(idValue); } return(value); } catch (NullReferenceException) { return(null); } }
public object GetValue(int i) { if (enumerator.Current == null) { return(null); } try { object value; try { value = currentEntityTypeSelectors[i](enumerator.Current); #if NET45 if (value is DbGeography dbgeo) { return(Provider.GetSqlGeography(dbgeo.WellKnownValue.WellKnownText, dbgeo.CoordinateSystemId)); } if (value is DbGeometry dbgeom) { return(Provider.GetSqlGeometry(dbgeom.WellKnownValue.WellKnownText, dbgeom.CoordinateSystemId)); } #endif } catch (KeyNotFoundException) { // current index is not present in given object type. i.e this column is for some sibling return(null); } if (Cols[i].IsNavigationProperty) { var col = Cols[i]; var pk = col.EntityMap.Pks.FirstOrDefault(); var navigationType = col.Type; if (pk == null) { return(0); } if (!Selectors.TryGetValue(navigationType, out Dictionary <int, Func <T, object> > navSelectors)) { if (pk == null) { return(0); } navSelectors = new Dictionary <int, Func <T, object> >(); var x = Expression.Parameter(enumerator.Current.GetType(), "x"); var propNames = $"{col.PropertyName}.{pk.PropertyName}".Split('.'); Expression propertyExpression = Expression.PropertyOrField(x, propNames[0]); propertyExpression = propNames.Skip(1).Aggregate(propertyExpression, Expression.PropertyOrField); var expression = Expression.Lambda <Func <T, object> >(Expression.Convert(propertyExpression, typeof(object)), x); var selector = expression.Compile(); navSelectors[i] = selector; Selectors[navigationType] = navSelectors; } return(navSelectors[i](enumerator.Current)); } return(value); } catch (NullReferenceException) { return(null); } }