private static async Task <Object> CreateNestedEntity(IOeDbEnumerator dbEnumerator, Object value, Type nestedEntityType, CancellationToken cancellationToken) { Object entity = dbEnumerator.Current; if (entity == null) { return(null); } if (dbEnumerator.EntryFactory.EdmNavigationProperty.Type.Definition is EdmCollectionType) { Type listType = typeof(List <>).MakeGenericType(new[] { nestedEntityType }); var list = (IList)Activator.CreateInstance(listType); do { Object item = dbEnumerator.Current; if (item != null) { list.Add(await CreateEntity(dbEnumerator, item, item, nestedEntityType, cancellationToken).ConfigureAwait(false)); } }while (await dbEnumerator.MoveNext(cancellationToken).ConfigureAwait(false)); return(list); } return(await CreateEntity(dbEnumerator, value, entity, nestedEntityType, cancellationToken).ConfigureAwait(false)); }
private static async Task <Object> CreateNestedEntity(IOeDbEnumerator dbEnumerator, Object value, Type nestedEntityType) { Object entity = dbEnumerator.Current; if (entity == null) { return(null); } if (dbEnumerator.EntryFactory.ResourceInfo.IsCollection.GetValueOrDefault()) { Type listType = typeof(List <>).MakeGenericType(new[] { nestedEntityType }); var list = (IList)Activator.CreateInstance(listType); do { Object item = dbEnumerator.Current; if (item != null) { list.Add(await CreateEntity(dbEnumerator, item, item, nestedEntityType).ConfigureAwait(false)); } }while (await dbEnumerator.MoveNextAsync().ConfigureAwait(false)); return(list); } return(await CreateEntity(dbEnumerator, value, entity, nestedEntityType).ConfigureAwait(false)); }
private static async Task SetNavigationProperty(IOeDbEnumerator dbEnumerator, Object value, Object entity, CancellationToken cancellationToken) { PropertyInfo propertyInfo = entity.GetType().GetProperty(dbEnumerator.EntryFactory.EdmNavigationProperty.Name); Type nestedEntityType = OeExpressionHelper.GetCollectionItemTypeOrNull(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; Object navigationValue = await CreateNestedEntity(dbEnumerator, value, nestedEntityType, cancellationToken).ConfigureAwait(false); propertyInfo.SetValue(entity, navigationValue); }
private static async Task SetNavigationProperty(IOeDbEnumerator dbEnumerator, Object value, Object entity) { PropertyInfo propertyInfo = entity.GetType().GetProperty(dbEnumerator.EntryFactory.ResourceInfo.Name); Type nestedEntityType = OeExpressionHelper.GetCollectionItemType(propertyInfo.PropertyType); if (nestedEntityType == null) { nestedEntityType = propertyInfo.PropertyType; } Object navigationValue = await CreateNestedEntity(dbEnumerator, value, nestedEntityType).ConfigureAwait(false); propertyInfo.SetValue(entity, navigationValue); }
private static async Task <Object> CreateEntity(IOeDbEnumerator dbEnumerator, Object value, Object entity, Type entityType, CancellationToken cancellationToken) { if (OeExpressionHelper.IsTupleType(entity.GetType())) { value = entity; entity = CreateEntityFromTuple(entityType, entity, dbEnumerator.EntryFactory.Accessors); } foreach (OeEntryFactory navigationLink in dbEnumerator.EntryFactory.NavigationLinks) { await SetNavigationProperty(dbEnumerator.CreateChild(navigationLink), value, entity, cancellationToken).ConfigureAwait(false); } return(entity); }