コード例 #1
0
        protected void UpdateAction(ResourceType resourceType, ResourceContainer resourceContainer, object entity)
        {
            AstoriaTestLog.WriteLine("Updating entity set :{0} , entity type :{1}", resourceContainer.Name, resourceType.Name);
            //Change any of the properties that make up the Etag
#if !ClientSKUFramework
            IEdmEntityType entityType = DataServiceMetadata.GetEntityType(entity);
            foreach (string eTagProperty in entityType.EtagProperties())
            {
                Type   propertyType = entity.GetType().GetProperty(eTagProperty).PropertyType;
                object newValue     = propertyType.GetTypedValue(eTagProperty, resourceType.Properties[eTagProperty].Facets.MaxSize);
                //entity.SetPropertyValue(eTagProperty, newValue);
            }
#endif

            CurrentContext.UpdateObject(entity);
            ExecuteAndValidate(() => { CurrentContext.SaveChanges(SaveChangeOption); });
        }
コード例 #2
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);
        }
コード例 #3
0
        protected void EnsureInsert(DataServiceContext context, object entity, string entitySetName, Workspace workspace, string skipEntitySet)
        {
#if !ClientSKUFramework
            IEdmEntityType entityType = null;
            if (DataServiceMetadata.ServiceMetadata == null)
            {
                DataServiceMetadata.LoadServiceMetadata(workspace.ServiceUri);
            }
            if (DataServiceMetadata.EntityTypes.Any(eType => eType.Name == entitySetName))
            {
                entityType = DataServiceMetadata.EntityTypes.First(eType => eType.Name == entitySetName);
            }
            if (entityType == null && DataServiceMetadata.EntityTypes.Any(eType => eType.Name == entity.GetType().Name))
            {
                entityType    = DataServiceMetadata.EntityTypes.First(eType => eType.Name == entity.GetType().Name);
                entitySetName = entity.GetType().Name;
            }
            if (entityType == null)
            {
                return;
            }
            foreach (IEdmNavigationProperty navProperty in entityType.NavigationProperties())
            {
                if (context.Links.All(ld => (ld.SourceProperty != navProperty.Name)))
                {
                    if (navProperty.TargetMultiplicity() == EdmMultiplicity.One && navProperty.Name != skipEntitySet)
                    {
                        IEdmEntityType navProperyEntityType = DataServiceMetadata.GetEntityType(navProperty);
                        ResourceType   resourceType         = workspace.ServiceContainer.ResourceTypes.First(rt => rt.Name == navProperyEntityType.Name);
                        object         instance             = resourceType.CreateInstance(false);
                        context.AddObject(navProperyEntityType.Name == "College" ? "Colleges" : navProperyEntityType.Name, instance);
                        context.SetLink(entity, navProperty.Name, instance);
                        context.SaveChangesDefaultOptions = SaveChangesOptions.BatchWithSingleChangeset;
                    }
                }
            }
#endif
        }