/// <summary> /// Implements IDataInserter.AddAssociation by creating a PUT/POST $ref request using cross-referencing, and adds it to the batch /// </summary> /// <param name="parent">Update tree of parent, must have already been added using AddEntity</param> /// <param name="property">Navigation property for the association</param> /// <param name="child">Update tree of child, must have already been added using AddEntity</param> public void AddAssociation(KeyedResourceInstance parent, ResourceProperty property, KeyedResourceInstance child) { // determine which verb to use // RequestVerb verb; if (property.OtherAssociationEnd.Multiplicity == Multiplicity.Many) verb = RequestVerb.Post; else verb = RequestVerb.Put; // create the request // AstoriaRequest request = workspace.CreateRequest(); request.Verb = verb; // use content-id cross referencing to link them // string parentContentId = contentIDMap[parent]; string childContentId = contentIDMap[child]; request.URI = "$" + parentContentId + "/" + property.Name + "/$ref"; request.Payload = "<adsm:uri xmlns:adsm=\"http://docs.oasis-open.org/odata/ns/metadata\">$" + childContentId + "</adsm:uri>"; // add it to the queue // queue.Add(request); // fire the event // if (this.OnAddingAssociation != null) OnAddingAssociation(parent, property, child); }
//Constructor public PredicateModel(Workspace w,ResourceContainer container, ResourceProperty p, KeyExpression parentKey, ResourceType resType) { _resourceContainer = container; _workspace = w; _resType = resType; _key = parentKey; _prop = p; }
public ResourceAssociationTypeEnd GetResourceAssociationTypeEnd(ResourceType resourceType, ResourceProperty resourceProperty) { ResourceAssociationTypeEnd[] associationTypeEndArray = new ResourceAssociationTypeEnd[2] { this.end1, this.end2 }; foreach (ResourceAssociationTypeEnd associationTypeEnd in associationTypeEndArray) { if (associationTypeEnd.ResourceType == resourceType && associationTypeEnd.ResourceProperty == resourceProperty) return associationTypeEnd; } return (ResourceAssociationTypeEnd)null; }
private ResourceProperty GetReferencedProperty(ResourceProperty prop) { switch (prop.ForeignKeys.Count()) { case 0: return prop; case 1: ForeignKey fk = prop.ForeignKeys.First(); if (fk.PrimaryKey.Properties.Count() == 1) return fk.PrimaryKey.Properties.Cast<ResourceProperty>().First(); break; } throw new Exception(String.Format("Property '{0}' does not map to a specific foreign property", prop)); }
public ResourceAssociationTypeEnd GetRelatedResourceAssociationSetEnd(ResourceType resourceType, ResourceProperty resourceProperty) { ResourceAssociationTypeEnd associationTypeEnd1 = this.GetResourceAssociationTypeEnd(resourceType, resourceProperty); if (associationTypeEnd1 != null) { ResourceAssociationTypeEnd[] associationTypeEndArray = new ResourceAssociationTypeEnd[2] { this.end1, this.end2 }; foreach (ResourceAssociationTypeEnd associationTypeEnd2 in associationTypeEndArray) { if (associationTypeEnd2 != associationTypeEnd1) return associationTypeEnd2; } } return (ResourceAssociationTypeEnd)null; }
public static ResourceInstanceProperty CreateRefInstanceProperty(KeyExpression keyExp, ResourceContainer container, ResourceProperty navProperty) { ResourceType navResourceType = navProperty.Type as ResourceType; ResourceInstanceKey resourceInstanceKey = ResourceInstanceKey.ConstructResourceInstanceKey(keyExp); return new ResourceInstanceNavRefProperty(navProperty.Name, new AssociationResourceInstance(resourceInstanceKey, AssociationOperation.Add)); }
public static ResourceInstanceProperty CreateProperty(ResourceProperty rp) { return CreateProperty(rp, false); }
private static string WriteProperty(ResourceProperty property) { List<string> facets = new List<string>(); if (property.PrimaryKey != null) { facets.Add("Id"); } if (property.Facets.ConcurrencyModeFixed) { facets.Add("ETag"); } if (property.Facets.IsClrProperty) { facets.Add("CanReflect"); } if (!property.Facets.IsDeclaredProperty) { facets.Add("Dynamic"); } if (facets.Count > 0) { return string.Format("{0} {1} ({2})", property.Type.FullName, property.Name, string.Join(", ", facets.ToArray())); } else { return string.Format("{0} {1}", property.Type.FullName, property.Name); } }
private static bool IsPropertyKind(ResourceProperty property, ResourcePropertyKind propertyKind) { return((property.Kind & propertyKind) == propertyKind); }
protected void CreateValueProperty(ResourceProperty property) { string propertyType = null; if (property.Type.ClrType != null) propertyType = property.Type.ClrType.Namespace + "." + property.Type.ClrType.Name; else propertyType = property.Type.Name; if (property.Facets.Nullable && (property.Type.ClrType != null && (property.Type.ClrType.IsPrimitive || property.Type.ClrType.IsValueType))) propertyType = "Nullable<" + propertyType + ">"; CodeBuilder.CreateFieldBackedProperty("_" + property.Name, property.Name, propertyType); }
public static int GetProgramResourceiv(int program, ProgramInterface intr, int index, ResourceProperty pname) { unsafe { int result = 0; glGetProgramResourceiv(program, intr, index, 1, &pname, 1, (int*) 0, &result); return result; } }
public AstoriaRequest Links(ResourceContainer container, KeyExpression keyExp, ResourceProperty property) { ExpNode q = Query.From( Exp.Variable(container)) .Where(keyExp) .Nav(property.Property(), true) .Select(); return _workspace.CreateRequest(q); }
private static ResourceInstanceComplexProperty ConvertComplexPayloadObjectToComplexProperty(ResourceProperty rp, PayloadComplexProperty payloadComplexProperty) { List<ResourceInstanceProperty> properties = new List<ResourceInstanceProperty>(); foreach (ResourceProperty childProperty in (rp.Type as ComplexType).Properties.OfType<ResourceProperty>()) { if (childProperty.IsComplexType) { PayloadComplexProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadComplexProperty; properties.Add(ConvertComplexPayloadObjectToComplexProperty(childProperty, fromPayload)); } else { PayloadSimpleProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadSimpleProperty; if (fromPayload != null) { ResourceInstanceProperty newProperty = null; object val = CommonPayload.DeserializeStringToObject(fromPayload.Value, childProperty.Type.ClrType, false, fromPayload.ParentObject.Format); newProperty = new ResourceInstanceSimpleProperty(childProperty.Name, new NodeValue(val, childProperty.Type)); properties.Add(newProperty); } } } ComplexResourceInstance complexResourceInstance = new ComplexResourceInstance(rp.Type.Name, properties.ToArray()); return new ResourceInstanceComplexProperty(rp.Type.Name, rp.Name, complexResourceInstance); }
public object GetPropertyValue(object target, ResourceProperty resourceProperty) { throw new NotImplementedException(); }
public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { throw new NotImplementedException(); }
public object AssembleIdentifiers( ResourceProfileData profileData, ResourceClassBase resource, AssociationView association = null) { if (profileData == null) { throw new ArgumentNullException(nameof(profileData)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (!resource.IdentifyingProperties.Any() && association == null) { return(ResourceRenderer.DoNotRenderProperty); } IList <ResourceProperty> properties; var activeResource = profileData.GetProfileActiveResource(resource); if (resource.IsAggregateRoot()) { properties = activeResource.IdentifyingProperties .OrderBy(x => x.PropertyName) .ToList(); } else { if (association != null) { properties = association.ThisProperties .Where(x => !(x.IsUnified && x.IsIdentifying)) .Select( x => association.PropertyMappingByThisName[x.PropertyName] .OtherProperty .ToResourceProperty(resource)) .OrderBy(x => x.PropertyName) .ToList(); } else { properties = resource.IdentifyingProperties .Where(x => !x.EntityProperty.IsLocallyDefined) .OrderBy(x => x.PropertyName) .ToList(); } } ResourceProperty first = properties.FirstOrDefault(); ResourceProperty last = properties.LastOrDefault(); return(properties.Any() ? properties.Select( y => new PropertyData(y) { IsFirstProperty = y == first, IsLastProperty = y == last }.Render()) .ToList() : ResourceRenderer.DoNotRenderProperty); }
public PSReferencedResourceSet(ResourceProperty referencedResourceProperty, ResourceType referenceeResourceType) { this.referenceResourceProperty = referencedResourceProperty; this.referenceeResourceType = referenceeResourceType; }
public NodeToExpressionTranslatorTests() { this.functionExpressionBinder = new FunctionExpressionBinder(t => { throw new Exception(); }); this.customerResourceType = new ResourceType(typeof(Customer), ResourceTypeKind.EntityType, null, "Fake", "Customer", false) { IsOpenType = true }; var derivedCustomerResourceType = new ResourceType(typeof(DerivedCustomer), ResourceTypeKind.EntityType, this.customerResourceType, "Fake", "DerivedCustomer", false); this.weaklyBackedDerivedType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, derivedCustomerResourceType, "Fake", "WeaklyBackedCustomer", false) { CanReflectOnInstanceType = false }; var nameResourceProperty = new ResourceProperty("Name", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))); this.customerResourceType.AddProperty(nameResourceProperty); var addressResourceType = new ResourceType(typeof(Address), ResourceTypeKind.ComplexType, null, "Fake", "Address", false); var addressResourceProperty = new ResourceProperty("Address", ResourcePropertyKind.ComplexType, addressResourceType); this.customerResourceType.AddProperty(addressResourceProperty); var namesResourceProperty = new ResourceProperty("Names", ResourcePropertyKind.Collection, ResourceType.GetCollectionResourceType(ResourceType.GetPrimitiveResourceType(typeof(string)))); this.customerResourceType.AddProperty(namesResourceProperty); var addressesResourceProperty = new ResourceProperty("Addresses", ResourcePropertyKind.Collection, ResourceType.GetCollectionResourceType(addressResourceType)); this.customerResourceType.AddProperty(addressesResourceProperty); var bestFriendResourceProperty = new ResourceProperty("BestFriend", ResourcePropertyKind.ResourceReference, this.customerResourceType); this.customerResourceType.AddProperty(bestFriendResourceProperty); var otherFriendsResourceProperty = new ResourceProperty("OtherFriends", ResourcePropertyKind.ResourceSetReference, this.customerResourceType); this.customerResourceType.AddProperty(otherFriendsResourceProperty); this.weaklyBackedResourceProperty = new ResourceProperty("WeaklyBacked", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false }; var guid1ResourceProperty = new ResourceProperty("Guid1", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(Guid))); var guid2ResourceProperty = new ResourceProperty("Guid2", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(Guid))); var nullableGuid1ResourceProperty = new ResourceProperty("NullableGuid1", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(Guid?))); var nullableGuid2ResourceProperty = new ResourceProperty("NullableGuid2", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(Guid?))); this.customerResourceType.AddProperty(guid1ResourceProperty); this.customerResourceType.AddProperty(guid2ResourceProperty); this.customerResourceType.AddProperty(nullableGuid1ResourceProperty); this.customerResourceType.AddProperty(nullableGuid2ResourceProperty); var resourceSet = new ResourceSet("Customers", this.customerResourceType); resourceSet.SetReadOnly(); var resourceSetWrapper = ResourceSetWrapper.CreateForTests(resourceSet, EntitySetRights.All); this.model = new EdmModel(); this.customerEdmType = new MetadataProviderEdmEntityType("Fake", this.customerResourceType, null, false, true, false, t => {}); this.model.AddElement(this.customerEdmType); this.derivedCustomerEdmType = new MetadataProviderEdmEntityType("Fake", derivedCustomerResourceType, this.customerEdmType, false, false, false, t => { }); this.model.AddElement(this.derivedCustomerEdmType); this.weaklyBackedCustomerEdmType = new MetadataProviderEdmEntityType("Fake", weaklyBackedDerivedType, this.derivedCustomerEdmType, false, false, false, t => { }); this.model.AddElement(this.weaklyBackedCustomerEdmType); this.nameProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, nameResourceProperty, EdmCoreModel.Instance.GetString(true), null); this.customerEdmType.AddProperty(this.nameProperty); var addressEdmType = new MetadataProviderEdmComplexType("Fake", addressResourceType, null, false, false, t => {}); this.model.AddElement(addressEdmType); this.addressProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, addressResourceProperty, new EdmComplexTypeReference(addressEdmType, true), null); this.customerEdmType.AddProperty(this.addressProperty); this.namesProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, namesResourceProperty, new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))), null); this.customerEdmType.AddProperty(this.namesProperty); this.addressesProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, addressesResourceProperty, new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressEdmType, false))), null); this.customerEdmType.AddProperty(this.addressesProperty); this.bestFriendNavigation = new MetadataProviderEdmNavigationProperty(this.customerEdmType, bestFriendResourceProperty, new EdmEntityTypeReference(this.customerEdmType, true)); this.customerEdmType.AddProperty(this.bestFriendNavigation); this.otherFriendsNavigation = new MetadataProviderEdmNavigationProperty(this.customerEdmType, otherFriendsResourceProperty, new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(this.customerEdmType, true)))); this.customerEdmType.AddProperty(this.otherFriendsNavigation); this.weaklyBackedProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, this.weaklyBackedResourceProperty, EdmCoreModel.Instance.GetString(true), null); this.customerEdmType.AddProperty(this.weaklyBackedProperty); var guid1EdmProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, guid1ResourceProperty, EdmCoreModel.Instance.GetGuid(false), null); this.customerEdmType.AddProperty(guid1EdmProperty); var guid2EdmProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, guid2ResourceProperty, EdmCoreModel.Instance.GetGuid(false), null); this.customerEdmType.AddProperty(guid2EdmProperty); var nullableGuid1EdmProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, nullableGuid1ResourceProperty, EdmCoreModel.Instance.GetGuid(true), null); this.customerEdmType.AddProperty(nullableGuid1EdmProperty); var nullableGuid2EdmProperty = new MetadataProviderEdmStructuralProperty(this.customerEdmType, nullableGuid2ResourceProperty, EdmCoreModel.Instance.GetGuid(true), null); this.customerEdmType.AddProperty(nullableGuid2EdmProperty); this.entitySet = new EdmEntitySetWithResourceSet(new EdmEntityContainer("Fake", "Container"), resourceSetWrapper, this.customerEdmType); ((EdmEntitySet)this.entitySet).AddNavigationTarget(this.bestFriendNavigation, this.entitySet); ((EdmEntitySet)this.entitySet).AddNavigationTarget(this.otherFriendsNavigation, this.entitySet); this.model.SetAnnotationValue(this.customerEdmType, this.customerResourceType); this.model.SetAnnotationValue(this.derivedCustomerEdmType, derivedCustomerResourceType); this.model.SetAnnotationValue(this.weaklyBackedCustomerEdmType, this.weaklyBackedDerivedType); this.model.SetAnnotationValue(this.nameProperty, nameResourceProperty); this.model.SetAnnotationValue(addressEdmType, addressResourceType); this.model.SetAnnotationValue(this.addressProperty, addressResourceProperty); this.model.SetAnnotationValue(this.namesProperty, namesResourceProperty); this.model.SetAnnotationValue(this.addressesProperty, addressesResourceProperty); this.model.SetAnnotationValue(this.bestFriendNavigation, bestFriendResourceProperty); this.model.SetAnnotationValue(this.otherFriendsNavigation, otherFriendsResourceProperty); this.model.SetAnnotationValue(this.weaklyBackedProperty, this.weaklyBackedResourceProperty); this.model.SetAnnotationValue(this.entitySet, resourceSetWrapper); this.model.SetAnnotationValue(guid1EdmProperty, guid1ResourceProperty); this.model.SetAnnotationValue(guid2EdmProperty, guid2ResourceProperty); this.model.SetAnnotationValue(nullableGuid1EdmProperty, nullableGuid1ResourceProperty); this.model.SetAnnotationValue(nullableGuid2EdmProperty, nullableGuid2ResourceProperty); this.testSubject = this.CreateTestSubject(); }
/// <summary> /// Returns ProperCaseSchemaName of the underlying entity. /// </summary> /// <param name="resourceProperty"></param> /// <returns></returns> public static string ProperCaseSchemaName(this ResourceProperty resourceProperty) { return resourceProperty.EntityProperty.Entity.DomainModel.SchemaNameMapProvider .GetSchemaMapByPhysicalName(resourceProperty.EntityProperty.Entity.Schema) .ProperCaseName; }
public static void SetExpandProperty(this RequestDescription requestDescription, ResourceProperty expandProperty) { requestDescription.SetAnnotation(ExpandPropertyAnnotationName, expandProperty); }
public void Navigation() { bool bfound = false; int j = 0; ResourceType _navType = null; while (!bfound && j < from.Properties.Count) { int i = this.Engine.Options.Random.Next( 0, from.Properties.Count ); ResourceProperty _property = (ResourceProperty)from.Properties[i]; if (_property.IsNavigation && _property.Type is CollectionType && this.ResContainer.BaseType.Properties.Contains( _property )) { if (_query is PredicateExpression) { _query = ((PredicateExpression)_query).Nav( _property.Property() ) as NavigationExpression; if (_property.Type is CollectionType) { _navType = (ResourceType)((ResourceCollection)_property.Type).SubType; _pType = _navType.ClientClrType; } else if (_property.Type is ResourceType) { _navType = (ResourceType)_property.Type; _pType = _property.Type.ClrType; } this.ResType = _navType; bNav = true; bfound = true; _action = LastAction.Nav; property = _property; this.ResType = _navType; //update the resourceType AstoriaTestLog.WriteLineIgnore( ".Nav(" + _property.Property().Name + ")" ); IsKey = false; } } j++; } }
public static void SetSpecialExpandOnLinksProperty(this RequestDescription requestDescription, ResourceProperty expandProperty) { requestDescription.SetAnnotation(SpecialExpandOnLinksPropertyAnnotationName, expandProperty); }
private static unsafe extern void glGetProgramResourceiv(int program, ProgramInterface intr, int index, int propcount, ResourceProperty* props, int buffsize, int* length, int* parameters);
public static void SetPropertyForPropertyOnlyOperation(this RequestDescription requestDescription, ResourceProperty property) { requestDescription.SetAnnotation(PropertyForPropertyOnlyOperationName, property); }
protected void CreateNavigationProperty(ResourceProperty navigationProperty) { string typeName=""; if (navigationProperty.Type is ResourceType) { typeName = navigationProperty.Type.Name; CodeBuilder.CreateFieldBackedProperty("_" + navigationProperty.Name, navigationProperty.Name, typeName); } else { CollectionType collectionType = navigationProperty.Type as CollectionType; typeName = CodeBuilder.CreateListOfTType(collectionType.SubType.Name); CodeBuilder.CreateFieldBackedProperty(typeName, navigationProperty.Name, true); } }
public AstoriaRequest EntitySetTopLevelWithSingleExpand(out ResourceContainer container, out ResourceProperty property) { container = _workspace.ServiceContainer.ResourceContainers .Where(c => c.ResourceTypes.Any(rt => rt.Properties.OfType<ResourceProperty>().Any(p => p.IsNavigation && p.Type is CollectionType))).Choose(); var properties = container.BaseType.Properties.OfType<ResourceProperty>(). Where(p => p.IsNavigation); if (properties.Count() > 0) { property = properties.Choose(); return EntitySetTopLevelWithSingleExpand(container, property); } else { container = null; property = null; return null; } }
public AstoriaRequest EntitySetTopLevelWithSingleExpand(ResourceContainer container, ResourceProperty property) { PropertyExpression[] expandValues = new PropertyExpression[] { new PropertyExpression(property) }; ExpNode q = Query.From( Exp.Variable(container)) .Expand(expandValues) .Select(); return _workspace.CreateRequest(q); }
public AstoriaRequest EntitySetNavProp(ResourceContainer container, KeyExpression keyExp, ResourceProperty property) { ExpNode q = Query.From( Exp.Variable(container)) .Where(keyExp) .Nav(property.Property()); return _workspace.CreateRequest(q); }
public static bool IsSafeLinkOperation(RequestVerb verb, ResourceContainer container, ResourceProperty property) { if (!property.IsNavigation) return false; if (property.Facets.UnsafeLinkOperations.Contains(verb)) return false; if (verb == RequestVerb.Get) return true; // astoria-level check switch(verb) { case RequestVerb.Patch: case RequestVerb.Put: if (property.OtherAssociationEnd.Multiplicity == Multiplicity.Many) return false; break; case RequestVerb.Post: if (property.OtherAssociationEnd.Multiplicity != Multiplicity.Many) return false; break; case RequestVerb.Delete: if (property.OtherAssociationEnd.Multiplicity == Multiplicity.One) return false; break; default: return false; } //// EF/DB level check if (container.Workspace.Database != null) { // would changing this nav-prop affect any foreign keys List<NodeProperty> affectedProperties = new List<NodeProperty>(); foreach (NodeProperty p in property.ResourceType.Properties) { if (!p.ForeignKeys.Any()) continue; ResourceType relatedType = (p.ForeignKeys.First().PrimaryKey.Properties.First() as ResourceProperty).ResourceType; if (relatedType == property.OtherAssociationEnd.ResourceType) affectedProperties.Add(p); } foreach (NodeProperty p in property.OtherAssociationEnd.ResourceType.Properties) { if (!p.ForeignKeys.Any()) continue; ResourceType relatedType = (p.ForeignKeys.First().PrimaryKey.Properties.First() as ResourceProperty).ResourceType; if (relatedType == property.ResourceType) affectedProperties.Add(p); } // can't change primary key by changing nav-prop if (affectedProperties.Any(p => p.PrimaryKey != null)) return false; if (verb == RequestVerb.Delete && affectedProperties.Any(p => !p.Facets.Nullable)) return false; if (container.Workspace.DataLayerProviderKind == DataLayerProviderKind.Edm && (verb == RequestVerb.Put || verb == RequestVerb.Patch)) { // EF: updating self-reference causes a null-reference in the mapping layer if (property.Type is ResourceType && property.OtherAssociationEnd.ResourceType == property.ResourceType) return false; } } return true; }
public AstoriaRequest SingleEntityKeyedNavProp(ResourceContainer container, KeyExpression keyExp, ResourceProperty property) { ExpNode q = Query.From( Exp.Variable(container)) .Where(keyExp) .Select(new PropertyExpression(property, false)); return _workspace.CreateRequest(q); }
public virtual KeyExpressions GetExistingAssociatedKeys(ResourceContainer resourceContainer, ResourceProperty property, KeyExpression keyExpression) { LinqQueryBuilder linqBuilder = new LinqQueryBuilder(this); ExpNode query = Query.From( Exp.Variable(resourceContainer)) .Where(keyExpression) .OfType(property.ResourceType) .Nav(new PropertyExpression(property)) .Select(); linqBuilder.Build(query); ResourceType associatedType = property.Type as ResourceType; if (property.Type is ResourceCollection) { associatedType = (property.Type as ResourceCollection).SubType as ResourceType; } IQueryable queryable = linqBuilder.QueryResult; KeyExpressions keys = new KeyExpressions(); IEnumerator enumerator = queryable.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current != null) { Type t = enumerator.Current.GetType(); if (AstoriaTestProperties.EdmObjectLayer == ServiceEdmObjectLayer.PocoWithProxy) t = t.BaseType; IEnumerable<ResourceType> typesWithName = resourceContainer.Workspace.ServiceContainer.ResourceTypes.Where(rt => (t.Name.Equals(rt.Name))); IEnumerable<ResourceType> typesWithNamespace = typesWithName.Where(rt2 => rt2.Namespace == t.Namespace).ToList(); ResourceType instanceType = typesWithNamespace.First(); ResourceContainer relatedContainer = resourceContainer.FindDefaultRelatedContainer(property); keys.Add(GetKeyExpression(relatedContainer, instanceType, enumerator.Current)); } } return keys; }
public AstoriaRequest PrimitivePropertyValue(out ResourceContainer container, out KeyExpression keyExp, out ResourceProperty property) { container = _workspace.ServiceContainer.ResourceContainers.Choose(); keyExp = _workspace.GetRandomExistingKey(container); property = container.BaseType.Properties.OfType<ResourceProperty>().Where(p => !p.IsNavigation && !p.IsComplexType).Choose(); return PrimitivePropertyValue(container, keyExp, property); }
public static ResourceInstanceProperty CreateProperty(ResourceProperty rp, bool createDollarValueVersion) { if (createDollarValueVersion == true && rp.IsComplexType) throw new ArgumentException("Cannot do a $Value of a ComplexType"); if (rp.IsComplexType) { return new ResourceInstanceComplexProperty(rp.Type.Name, rp.Name, CreateComplexResourceInstance((ComplexType)rp.Type)); } else if (!rp.IsNavigation) { NodeValue nodeValue = Resource.CreateValue(rp); return new ResourceInstanceSimpleProperty(rp.Name, nodeValue, createDollarValueVersion); } else throw new ArgumentException("Property has to be a complex type or simple property"); }
public AstoriaRequest PrimitivePropertyValue(ResourceContainer container, KeyExpression keyExp, ResourceProperty property) { ExpNode q = Query.From( Exp.Variable(container)) .Where(keyExp) .Select(new PropertyExpression(property, true)); return _workspace.CreateRequest(q); }
public static ResourceInstanceProperty CreateCollectionInstanceProperty(KeyExpressions keyExps, ResourceContainer container, ResourceProperty navProperty) { ResourceType navResourceType = (navProperty.Type as CollectionType).SubType as ResourceType; List<AssociationResourceInstance> associationNodes = new List<AssociationResourceInstance>(); foreach (KeyExpression associatedKey in keyExps) { ResourceInstanceKey resourceInstanceKey = ResourceInstanceKey.ConstructResourceInstanceKey(associatedKey); associationNodes.Add(new AssociationResourceInstance(resourceInstanceKey, AssociationOperation.Add)); } if (associationNodes.Count > 0) { ResourceInstanceNavColProperty navigationProperty = new ResourceInstanceNavColProperty(navProperty.Name, associationNodes.ToArray()); return navigationProperty; } return null; }
public AstoriaRequest Links(out ResourceContainer container, out KeyExpression keyExp, out ResourceProperty property) { container = _workspace.ServiceContainer.ResourceContainers .Where(c => c.ResourceTypes.Any(rt => rt.Properties.OfType<ResourceProperty>().Any(p => p.IsNavigation && p.Type is CollectionType))).Choose(); keyExp = _workspace.GetRandomExistingKey(container); property = container.BaseType.Properties.OfType<ResourceProperty>().Where(p => p.IsNavigation && p.Type is CollectionType).Choose(); return Links(container, keyExp, property); }
/// <summary> /// Implements IDataInserter.AddAssociation by generating the appropriate IUpdatable.AddReferenceToCollection or IUpdatable.SetReference call /// </summary> /// <param name="parent">Update tree of parent, must have already been added using AddEntity</param> /// <param name="property">Navigation property for the association</param> /// <param name="child">Update tree of child, must have already been added using AddEntity</param> public void AddAssociation(KeyedResourceInstance parent, ResourceProperty property, KeyedResourceInstance child) { // look up the object names for these entities // string parentObjectName = entityListName + "[" + entityIDs[parent] + "]"; string childObjectName = entityListName + "[" + entityIDs[child] + "]"; // code-gen the appropriate IUpdatable call // code.AppendLine("//Adding association"); if (property.OtherAssociationEnd.Multiplicity == Multiplicity.Many) code.AppendLine("updatable.AddReferenceToCollection(" + parentObjectName + ", \"" + property.Name + "\", " + childObjectName + ");"); else code.AppendLine("updatable.SetReference(" + parentObjectName + ", \"" + property.Name + "\", " + childObjectName + ");"); code.AppendLine(); // Fire the event // if (this.OnAddingAssociation != null) OnAddingAssociation(parent, property, child); // ensure that a later Flush/Close will write the SaveChanges call changesSaved = false; }
/// <summary> /// Check property has any associations (this could be a reference and/or unified key) /// </summary> /// <param name="property"></param> /// <returns></returns> public static bool HasAssociations(this ResourceProperty property) { return property.EntityProperty.IncomingAssociations.Any(); }