private IEdmProperty CreateEdmProperty(IEdmStructuredType declaringType, PropertyInfo propertyInfo) { IEdmProperty property; IEdmType edmType = this.GetOrCreateEdmTypeInternal(propertyInfo.PropertyType).EdmType; bool isNullable = ClientTypeUtil.CanAssignNull(propertyInfo.PropertyType); if ((edmType.TypeKind == EdmTypeKind.Entity) || ((edmType.TypeKind == EdmTypeKind.Collection) && (((IEdmCollectionType) edmType).ElementType.TypeKind() == EdmTypeKind.Entity))) { IEdmEntityType type2 = declaringType as IEdmEntityType; if (type2 == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientTypeCache_NonEntityTypeCannotContainEntityProperties(propertyInfo.Name, propertyInfo.DeclaringType.ToString())); } property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo.Name, edmType.ToEdmTypeReference(isNullable), null, false, EdmOnDeleteAction.None, "Partner", type2.ToEdmTypeReference(true), null, false, EdmOnDeleteAction.None); } else { property = new EdmStructuralProperty(declaringType, propertyInfo.Name, edmType.ToEdmTypeReference(isNullable)); } property.SetClientPropertyAnnotation(new ClientPropertyAnnotation(property, propertyInfo, this.protocolVersion)); return property; }
public EdmStructuralProperty AddStructuralProperty(string name, EdmPrimitiveTypeKind type, bool isNullable) { EdmStructuralProperty edmStructuralProperty = new EdmStructuralProperty(this, name, EdmCoreModel.Instance.GetPrimitive(type, isNullable)); this.AddProperty(edmStructuralProperty); return edmStructuralProperty; }
public EdmStructuralProperty AddStructuralProperty(string name, IEdmTypeReference type, string defaultValue, EdmConcurrencyMode concurrencyMode) { EdmStructuralProperty edmStructuralProperty = new EdmStructuralProperty(this, name, type, defaultValue, concurrencyMode); this.AddProperty(edmStructuralProperty); return edmStructuralProperty; }
public EdmStructuralProperty AddStructuralProperty(string name, IEdmTypeReference type) { EdmStructuralProperty edmStructuralProperty = new EdmStructuralProperty(this, name, type); this.AddProperty(edmStructuralProperty); return edmStructuralProperty; }
private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConfiguration config) { foreach (PropertyConfiguration property in config.Properties) { switch (property.Kind) { case PropertyKind.Primitive: PrimitivePropertyConfiguration primitiveProperty = property as PrimitivePropertyConfiguration; EdmPrimitiveTypeKind typeKind = GetTypeKind(primitiveProperty.PropertyInfo.PropertyType); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( typeKind, primitiveProperty.OptionalProperty); var primitiveProp = new EdmStructuralProperty( type, primitiveProperty.PropertyInfo.Name, primitiveTypeReference); type.AddProperty(primitiveProp); // Set Annotation StoreGeneratedPattern if (config.Kind == EdmTypeKind.Entity && primitiveProperty.StoreGeneratedPattern != DatabaseGeneratedOption.None) { _directValueAnnotations.Add( new StoreGeneratedPatternAnnotation(primitiveProp, primitiveProperty.StoreGeneratedPattern)); } break; case PropertyKind.Complex: ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration; IEdmComplexType complexType = _types[complexProperty.RelatedClrType] as IEdmComplexType; type.AddStructuralProperty( complexProperty.PropertyInfo.Name, new EdmComplexTypeReference(complexType, complexProperty.OptionalProperty)); break; case PropertyKind.Collection: CollectionPropertyConfiguration collectionProperty = property as CollectionPropertyConfiguration; IEdmTypeReference elementTypeReference = null; if (_types.ContainsKey(collectionProperty.ElementType)) { IEdmComplexType elementType = _types[collectionProperty.ElementType] as IEdmComplexType; elementTypeReference = new EdmComplexTypeReference(elementType, false); } else { elementTypeReference = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(collectionProperty.ElementType); } type.AddStructuralProperty( collectionProperty.PropertyInfo.Name, new EdmCollectionTypeReference( new EdmCollectionType(elementTypeReference), collectionProperty.OptionalProperty)); break; default: break; } } }
/// <summary> /// Creates and adds a nullable structural property to this type. /// </summary> /// <param name="name">Name of the property.</param> /// <param name="type">Type of the property.</param> /// <returns>Created structural property.</returns> public EdmStructuralProperty AddStructuralProperty(string name, EdmPrimitiveTypeKind type) { EdmStructuralProperty property = new EdmStructuralProperty(this, name, EdmCoreModel.Instance.GetPrimitive(type, true)); this.AddProperty(property); return property; }
private void CreatePrimitiveProperty(PrimitivePropertyConfiguration primitiveProperty, EdmStructuredType type, StructuralTypeConfiguration config, out IEdmProperty edmProperty) { EdmPrimitiveTypeKind typeKind = GetTypeKind(primitiveProperty.PropertyInfo.PropertyType); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( typeKind, primitiveProperty.OptionalProperty); // Set concurrency token if is entity type, and concurrency token is true EdmConcurrencyMode concurrencyMode = EdmConcurrencyMode.None; if (config.Kind == EdmTypeKind.Entity && primitiveProperty.ConcurrencyToken) { concurrencyMode = EdmConcurrencyMode.Fixed; } var primitiveProp = new EdmStructuralProperty( type, primitiveProperty.PropertyInfo.Name, primitiveTypeReference, defaultValueString: null, concurrencyMode: concurrencyMode); type.AddProperty(primitiveProp); edmProperty = primitiveProp; // Set Annotation StoreGeneratedPattern if (config.Kind == EdmTypeKind.Entity && primitiveProperty.StoreGeneratedPattern != DatabaseGeneratedOption.None) { _directValueAnnotations.Add( new StoreGeneratedPatternAnnotation(primitiveProp, primitiveProperty.StoreGeneratedPattern)); } }