/// <summary> /// Populates a contract description from a domain service description. /// </summary> /// <param name="contractDesc">Contract description to populate.</param> /// <param name="domainServiceDescription">Domain service description.</param> private void LoadContractDescription(ContractDescription contractDesc, DomainServiceDescription domainServiceDescription) { OperationDescription operationDesc; Debug.Assert(this.domainDataServiceMetadata != null, "this.domainDataServiceMetadata != null"); // Create contract operations by inferring them from the [Query] & [Invoke] methods on the domain service. foreach (DomainOperationEntry operation in domainServiceDescription.DomainOperationEntries) { if (this.domainDataServiceMetadata.Sets.ContainsKey(operation.Name) || this.domainDataServiceMetadata.ServiceOperations.ContainsKey(operation.Name)) { switch (operation.Operation) { case DomainOperation.Query: operationDesc = ODataEndpointFactory.CreateQueryOperationDescription(contractDesc, operation); Type queryOperationType = typeof(DomainDataServiceQueryOperationBehavior <>).MakeGenericType(operation.AssociatedType); // Add as first behavior such that our operation invoker is the first in the chain. operationDesc.Behaviors.Insert(0, (IOperationBehavior)Activator.CreateInstance(queryOperationType, operation)); contractDesc.Operations.Add(operationDesc); break; case DomainOperation.Invoke: operationDesc = ODataEndpointFactory.CreateOperationDescription(contractDesc, operation); // Add as first behavior such that our operation invoker is the first in the chain. operationDesc.Behaviors.Insert(0, new DomainDataServiceInvokeOperationBehavior(operation)); contractDesc.Operations.Add(operationDesc); break; default: break; } } } }
/// <summary> /// Create operation corresponding to given DomainService query operation. /// </summary> /// <param name="declaringContract">Contract to which operation will belong.</param> /// <param name="operation">DomainService query operation.</param> /// <returns>Created operation.</returns> private static OperationDescription CreateQueryOperationDescription(ContractDescription declaringContract, DomainOperationEntry operation) { OperationDescription operationDesc = ODataEndpointFactory.CreateOperationDescription(declaringContract, operation); // Change the return type to QueryResult<TEntity>. operationDesc.Messages[1].Body.ReturnValue.Type = typeof(IEnumerable <>).MakeGenericType(operation.AssociatedType); return(operationDesc); }