Skip to content

Instantly share code, notes, and snippets.


Mark Stafford markdstafford

  • Microsoft
  • Redmond, WA
View GitHub Profile
View example1.cs
context.Configurations.ResponsePipeline.OnEntryEnded((a =>
Type entityType = dataServiceContext.ResolveType(a.Entry.TypeName);
if (typeof(Product).IsAssignableFrom(entityType))
var properties = a.Entry.Properties as List<ODataProperty>;
if (properties == null)
properties = new List<ODataProperty>(a.Entry.Properties);
View 01. retrieve Northwind products - jQuery.js
var queryString = ("/Northwind.svc/Products?"
+ "$filter=((Category/Category_ID eq 1)or"
+ "substringof('tofu',tolower"
+ "$orderby=Category/Category_Name&"
+ "$select=Product_Name");
url: queryString,
dataType: 'JSON',
View Snippet1.cs
using System.Data.Services;
namespace OData101.UpdateTheSvcFileWhenBinDeploying
public class BinDeploy : DataService&lt;DummyContext&gt; { }
public class DummyContext { }
markdstafford / Snippet1.cs
Last active Dec 16, 2015
Code for OData 101: Using the [NotMapped] attribute to exclude Enum properties
View Snippet1.cs
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace WcfDataServices101.UsingTheNotMappedAttribute
public class AccessControlEntry
public int Id { get; set; }
// An Enum property cannot be mapped to an OData feed, so it must be
markdstafford / Snippet1.json
Last active Dec 16, 2015
Code for OData 101: What is JSON Light?
View Snippet1.json
"Description":"Whole grain bread",
markdstafford / Program.cs
Created Apr 25, 2013
Code for OData 101: Building our first OData consumer
View Program.cs
using System;
using System.Linq;
namespace OData101.BuildingOurFirstODataConsumer
internal class Program
private static void Main()
var context = new Netflix.NetflixCatalog(new Uri(""));
markdstafford / Snippet1.cs
Last active Dec 16, 2015
Code for OData 101: Building our first OData-based Windows Store app (Part 2)
View Snippet1.cs
public static async Task<IEnumerable<T>> ExecuteAsync<T>(this DataServiceQuery<T> query)
return await Task.Factory.FromAsync<IEnumerable<T>>(query.BeginExecute(null, null), query.EndExecute);
View Data Visualization Usage.xml
<!--A marked-up model available from some $metadata endpoint-->
<Using Namespace="org.odata.v1" Alias="odata" />
<Using Namespace="" Alias="geoflow" />
<Using Namespace="" Alias="dataViz" />
<Using Namespace="com.tableau.visualization.v1" Alias="tableau" />
<!--Crimes (e.g., robbery, arson, etc.) that occurred in the past. This entity type can be queried
via "normal" OData by using the Incidents entity set, but it is also marked up with visualization
View gist:5135588
IEdmModel model = EdmxReader.Parse(XmlReader.Create("$metadata"));
IEdmEntityType product = model.FindDeclaredType("ODataDemo.Product") as IEdmEntityType;
var orderby = ODataUriParser.ParseOrderBy("ReleaseDate desc", model, product);
var filter = ODataUriParser.ParseFilter("ReleaseDate ge datetime'2012-11-19T00:00:00Z'", model, product);
markdstafford / SampleDataSource.cs
Created Aug 21, 2012
Sample Windows Store app with OData consumption
View SampleDataSource.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Data.Services.Client;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OData.WindowsStore.NetflixDemo.Common;