/// <summary>
        /// Generates an assembly that contains the object layer types for the given EntityModelSchema
        /// </summary>
        /// <param name="workspace">test workspace under construction</param>
        /// <param name="schema">The schema under test</param>
        /// <returns>An assembly that contains the object layer types for the given EntityModelSchema</returns>
        private Assembly GenerateObjectLayer(ODataTestWorkspace workspace, EntityModelSchema schema)
        {
            CodeCompileUnit objectLayerCompileUnit = new CodeCompileUnit();

            this.ObjectLayerCodeGenerator.GenerateObjectLayer(objectLayerCompileUnit, schema);
            string objectLayerCode;

            using (var writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                this.Language.CreateCodeGenerator().GenerateCodeFromCompileUnit(objectLayerCompileUnit, writer, null);
                objectLayerCode = writer.ToString();
            }

            string outputFilePath = Guid.NewGuid().ToString();

#if SILVERLIGHT
            outputFilePath = String.Format("{0}Assembly.dll", outputFilePath);
            return(typeof(DefaultNamespace.Phone).Assembly);
#else
            outputFilePath = outputFilePath + ".dll";
            this.Language.CompileAssemblyFromSource(outputFilePath, new[] { objectLayerCode }, referenceAssemblies);
            var assembly = AssemblyHelpers.LoadAssembly(outputFilePath, referenceAssemblies);
            return(assembly);
#endif
        }
        /// <summary>
        /// Returns a Workspace
        /// </summary>
        /// <param name="modelSchema">model schema</param>
        /// <returns> An OData Workspace </returns>
        public Workspace BuildWorkspace(EntityModelSchema modelSchema)
        {
            // Note this must be done after the binary fixup, as we replace binary keys with integer ones, but before the provider-specific fixup
            this.PrimitiveTypeResolver.ResolveProviderTypes(modelSchema, new EdmDataTypeResolver());
            new SetDefaultCollectionTypesFixup().Fixup(modelSchema);
            new SetDefaultDataServiceConfigurationBehaviors().Fixup(modelSchema);
            new RemoveHigherVersionFeaturesFixup(DataServiceProtocolVersion.V4).Fixup(modelSchema);
            ODataTestWorkspace workspace = new ODataTestWorkspace();

            workspace.ConceptualModel     = modelSchema;
            workspace.ObjectLayerAssembly = this.GenerateObjectLayer(workspace, modelSchema);
            return(workspace);
        }
        /// <summary>
        /// Returns a Workspace
        /// </summary>
        /// <param name="modelSchema">model schema</param>
        /// <returns> An OData Workspace </returns>
        public Workspace BuildWorkspace(EntityModelSchema modelSchema)
        {
            // Note this must be done after the binary fixup, as we replace binary keys with integer ones, but before the provider-specific fixup
            this.PrimitiveTypeResolver.ResolveProviderTypes(modelSchema, new EdmDataTypeResolver());
            new SetDefaultCollectionTypesFixup().Fixup(modelSchema);
            new SetDefaultDataServiceConfigurationBehaviors().Fixup(modelSchema);
            new RemoveHigherVersionFeaturesFixup(DataServiceProtocolVersion.V4).Fixup(modelSchema);
            ODataTestWorkspace workspace = new ODataTestWorkspace();

            workspace.ConceptualModel = modelSchema;
            workspace.ObjectLayerAssembly = this.GenerateObjectLayer(workspace, modelSchema);
            return workspace;
        }
        /// <summary>
        /// Generates an assembly that contains the object layer types for the given EntityModelSchema
        /// </summary>
        /// <param name="workspace">test workspace under construction</param> 
        /// <param name="schema">The schema under test</param>
        /// <returns>An assembly that contains the object layer types for the given EntityModelSchema</returns>
        private Assembly GenerateObjectLayer(ODataTestWorkspace workspace, EntityModelSchema schema)
        {
            CodeCompileUnit objectLayerCompileUnit = new CodeCompileUnit();
            this.ObjectLayerCodeGenerator.GenerateObjectLayer(objectLayerCompileUnit, schema);
            string objectLayerCode;
            using (var writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                this.Language.CreateCodeGenerator().GenerateCodeFromCompileUnit(objectLayerCompileUnit, writer, null);
                objectLayerCode = writer.ToString();
            }

            string outputFilePath = Guid.NewGuid().ToString();
#if SILVERLIGHT
            outputFilePath = String.Format("{0}Assembly.dll", outputFilePath);
            return typeof(DefaultNamespace.Phone).Assembly;
#else
            outputFilePath = outputFilePath + ".dll";
            this.Language.CompileAssemblyFromSource(outputFilePath, new[] { objectLayerCode }, referenceAssemblies);
            var assembly = AssemblyHelpers.LoadAssembly(outputFilePath, referenceAssemblies);
            return assembly;
#endif
        }