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 }
public virtual void ForEachResourceType(Action <ResourceType, ResourceContainer, Workspace> someAction, bool workspaceShouldUpdate) { Func <ResourceType, bool> typeHasConcurrencyTokens = (resourceType) => { bool hasConcurrencyTokens = false; foreach (ResourceProperty property in resourceType.Properties.OfType <ResourceProperty>()) { if (property.Facets.ConcurrencyMode == ConcurrencyMode.Fixed) { hasConcurrencyTokens = true; break; } } return(hasConcurrencyTokens); }; foreach (Workspace workspace in this) { bool doneProcessing = false; DataServiceMetadata.LoadServiceMetadata(workspace.ServiceUri); if (workspaceShouldUpdate && !workspace.Settings.SupportsUpdate) { throw (new TestSkippedException("Workspace does not support updating")); } foreach (ResourceContainer container in workspace.ServiceContainer.ResourceContainers) { foreach (ResourceType resourceType in container.ResourceTypes.Where(rType => (!workspaceShouldUpdate || rType.IsInsertable) && typeHasConcurrencyTokens(rType))) { try { //Filter only types which have base types , if required if (!SkipType(resourceType, workspaceShouldUpdate)) { doneProcessing = true; someAction(resourceType, container, workspace); } } catch (OptimisticConcurrencyException oException) { throw oException; } catch (Exception exception) { if (!(exception is OptimisticConcurrencyException)) { AstoriaTestLog.FailAndContinue(exception); } } if (doneProcessing) { break; } } if (doneProcessing) { break; } } } }