コード例 #1
0
        protected void SetPropertyValues(
            IBindableModelContext context,
            IEntitySet navigationRoot,
            IEntity targetEntity,
            ODataEntityDto oDataEntity,
            IEnumerable <string> propertiesToExclude)
        {
            var entityType         = oDataEntity.GetEntityType(context);
            var relevantProperties = oDataEntity.Entry.Properties.Where(p => !propertiesToExclude.Contains(p.Name));

            foreach (var property in relevantProperties)
            {
                IStructuralProperty structuralProperty;
                if (entityType.TryGetStructuralProperty(property.Name, out structuralProperty))
                {
                    if (!this.TryHandleStructuralProperty(targetEntity, oDataEntity, structuralProperty))
                    {
                        throw new InvalidOperationException("The included structural property \"" + property.Name + "\" could not be processed.");
                    }

                    continue;
                }

                INavigationProperty navigationProperty;
                if (entityType.TryGetNavigationProperty(property.Name, out navigationProperty))
                {
                    if (!this.TryHandleNavigationProperty(context, targetEntity, oDataEntity, navigationProperty, navigationRoot))
                    {
                        throw new InvalidOperationException("The included navigation property \"" + property.Name + "\" could not be processed.");
                    }

                    continue;
                }

                throw new NotSupportedException("The included property \"" + property.Name + "\" is unsupported.");
            }
        }