Skip to content

Instantly share code, notes, and snippets.

Avatar

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"
+"(Product_Name)))&"
+ "$orderby=Category/Category_Name&"
+ "$select=Product_Name");
$.ajax({
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
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
markdstafford / Snippet1.json
Last active Dec 16, 2015
Code for OData 101: What is JSON Light?
View Snippet1.json
{
"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 / 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("http://odata.netflix.com/Catalog"));
@markdstafford
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-->
<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
View gist:5135588
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);
@markdstafford
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;