Esempio n. 1
0
        protected void InsertReferenceNavProperty()
        {
            ForEachResourceType(
                (resourceType, resourceContainer, workspace) =>
            {
                CreateContext(resourceType, workspace);
#if !ClientSKUFramework
                object entity = ExecuteURI(resourceType, String.Format("/{0}", resourceContainer.Name));
                Uri entityUri = null;


                IEdmEntityType entityType = DataServiceMetadata.GetEntityType(entity);
                if (entityType == null)
                {
                    return;
                }
                CurrentContext.TryGetUri(entity, out entityUri);
                foreach (string refNavProperty in entityType.ReferenceNavigationProperties())
                {
                    ResourceType navResType = workspace.ServiceContainer.ResourceTypes.FirstOrDefault(rt => rt.Name == refNavProperty);
                    if (navResType != null)
                    {
                        object navEntity      = navResType.CreateInstance(false);
                        string navPropertyURI = String.Format("{0}/{1}", entityUri.Segments[entityUri.Segments.Length - 1], refNavProperty);
                        CurrentContext.AddObject(navPropertyURI, navEntity);
                        CurrentContext.EnsureInsert(navEntity, navResType);
                    }
                }
                ExecuteAndValidate(() => CurrentContext.SaveChanges(SaveChangeOption));
                if (ContinueTest)
                {
                    if (ChainedFunction != null)
                    {
                        ChainedFunction();
                    }
                }
#endif
            }, true);
        }