Skip to content

Instantly share code, notes, and snippets.

View markdstafford's full-sized avatar

Mark Stafford markdstafford

  • Microsoft
  • Redmond, WA
View GitHub Profile
@markdstafford
markdstafford / program.cs
Created July 10, 2012 15:12
AddLink/DetachLink
using System;
using System.Linq;
using Scratch.RW;
namespace Scratch
{
internal class Program
{
private static DemoService demoService;
private static Category category;
@markdstafford
markdstafford / program.cs
Created July 11, 2012 19:23
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;
@markdstafford
markdstafford / scratchservice.svc.cs
Created July 12, 2012 21:36
Sample service operation
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace Scratch.Web
{
@markdstafford
markdstafford / SampleDataSource.cs
Created August 21, 2012 20:44
Sample Windows Store app with OData consumption
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;
IEdmModel model = EdmxReader.Parse(XmlReader.Create("http://services.odata.org/v3/odata/odata.svc/$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);
<!--A marked-up model available from some $metadata endpoint-->
<Schema>
<Using Namespace="org.odata.v1" Alias="odata" />
<Using Namespace="com.microsoft.geoflow.v1" Alias="geoflow" />
<Using Namespace="org.odata.data.visualization.v1" 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
@markdstafford
markdstafford / Snippet1.cs
Last active December 16, 2015 15:28
Code for OData 101: Building our first OData-based Windows Store app (Part 2)
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);
}
@markdstafford
markdstafford / Program.cs
Created April 25, 2013 01:56
Code for OData 101: Building our first OData consumer
using System;
using System.Linq;
namespace OData101.BuildingOurFirstODataConsumer
{
internal class Program
{
private static void Main()
{
var context = new Netflix.NetflixCatalog(new Uri("http://odata.netflix.com/Catalog"));
@markdstafford
markdstafford / Snippet1.json
Last active December 16, 2015 15:39
Code for OData 101: What is JSON Light?
{
"odata.metadata":"http://services.odata.org/Experimental/OData/OData.svc/$metadata#ODataDemo.DemoService/Products/@Element",
"ID":0,
"Name":"Bread",
"Description":"Whole grain bread",
"ReleaseDate":"1992-01-01T00:00:00",
"DiscontinuedDate":null,
"Rating":4,
"Price":"2.5"
}
@markdstafford
markdstafford / Snippet1.cs
Last active December 16, 2015 16:09
Code for OData 101: Using the [NotMapped] attribute to exclude Enum properties
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