/// <summary> /// Generates the [DataServiceKey] attribute on a given client type /// </summary> /// <param name="entityType">The complex type's metadata</param> /// <param name="entityTypeClass">The complex types declaration</param> protected override void GenerateKeyAttribute(EntityType entityType, CodeTypeDeclaration entityTypeClass) { if (entityType.Annotations.OfType <ClientTypeHasNoKeysAnnotation>().Any()) { this.GenerateDataServiceEntityAttribute(entityTypeClass); } else { base.GenerateKeyAttribute(entityType, entityTypeClass); } DataServiceEntitySetAnnotation entitySetAnnotation = entityType.Annotations.OfType <DataServiceEntitySetAnnotation>().SingleOrDefault(); if (entitySetAnnotation != null) { this.GenerateEntitySetAttribute(entityTypeClass, entitySetAnnotation); } }
/// <summary> /// Adds the [EntitySet('setName')] attribute on the client type /// </summary> /// <param name="entityTypeClass">The class declaration for the client type</param> /// <param name="entitySetAnnotation">The DataServiceEntitySetAnnotation which contains the name of the set</param> private void GenerateEntitySetAttribute(CodeTypeDeclaration entityTypeClass, DataServiceEntitySetAnnotation entitySetAnnotation) { var entitySetAttribute = entityTypeClass.AddCustomAttribute(Code.TypeRef("EntitySet")); entitySetAttribute.Arguments.Add(new CodeAttributeArgument(Code.Primitive(entitySetAnnotation.EntitySetName))); }