Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Sample JSON Light client
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.Data.Edm;
using Microsoft.Data.Edm.Csdl;
using Microsoft.Data.Edm.Validation;
using Scratch.NW;
namespace Scratch
internal class Program
private static readonly Dictionary<Uri, IEdmModel> models = new Dictionary<Uri, IEdmModel>();
private static void Main()
var context = new NorthwindEntities(new Uri(""));
// Note that for the release, code gen will likely provide a much friendlier alternative to this example
context.Format.UseJson(args =>
Uri metadataUri = args.MetadataDocumentUri;
if (!models.ContainsKey(metadataUri))
var xmlTextReader = new XmlTextReader(metadataUri.ToString());
IEdmModel edmModel = null;
IEnumerable<EdmError> errors = null;
if (EdmxReader.TryParse(xmlTextReader, out edmModel, out errors))
models[metadataUri] = edmModel;
var errorMessageBuilder = new StringBuilder("Model creation failed; please resolve the following errors in the metadata document:");
foreach (EdmError error in errors)
errorMessageBuilder.AppendLine(String.Format("\t{0}", error.ErrorMessage));
throw new Exception(errorMessageBuilder.ToString());
return new ModelResolverResult
ServiceModel = models[metadataUri]
Category category = context.Categories.First();
foreach (Sales_Totals_by_Amount item in context.Sales_Totals_by_Amounts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.