protected Object CreateEntity(ODataResource resource, IReadOnlyList <NavigationPorperty> navigationProperties) { Db.OeEntitySetMetaAdapter entitySetMetaAdapter = EntitySetMetaAdapters.FindByTypeName(resource.TypeName); Object entity = OeEntityItem.CreateEntity(entitySetMetaAdapter.EntityType, resource); Dictionary <PropertyInfo, ODataResourceSetBase> propertyInfos = null; foreach (NavigationPorperty navigationProperty in navigationProperties) { PropertyInfo clrProperty = entitySetMetaAdapter.EntityType.GetProperty(navigationProperty.Name); Object value = navigationProperty.Value; if (navigationProperty.ResourceSet == null || (navigationProperty.ResourceSet.Count == null && navigationProperty.ResourceSet.NextPageLink == null)) { clrProperty.SetValue(entity, value); continue; } if (value == null && navigationProperty.ResourceSet.NextPageLink != null) { value = CreateCollection(clrProperty.PropertyType); } clrProperty.SetValue(entity, value); if (value is IEnumerable collection) { NavigationProperties.Add(collection, navigationProperty.ResourceSet); if (propertyInfos == null) { propertyInfos = new Dictionary <PropertyInfo, ODataResourceSetBase>(navigationProperties.Count); NavigationPropertyEntities.Add(entity, propertyInfos); } propertyInfos.Add(clrProperty, navigationProperty.ResourceSet); } } return(entity); }
private Object CreateEntity(StackItem stackItem) { var entry = (ODataResource)stackItem.Item; if (entry == null) { return(null); } var entitySetMetaAdapter = _entitySetMetaAdapters.FindByTypeName(entry.TypeName); var entity = OeEntityItem.CreateEntity(entitySetMetaAdapter.EntityType, entry); if (stackItem.NavigationProperties.Count > 0) { PropertyDescriptorCollection clrProperties = TypeDescriptor.GetProperties(entitySetMetaAdapter.EntityType); foreach (var navigationProperty in stackItem.NavigationProperties) { PropertyDescriptor clrProperty = clrProperties[navigationProperty.Key]; clrProperty.SetValue(entity, navigationProperty.Value); } } return(entity); }