Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.