Skip to content

Instantly share code, notes, and snippets.

View markdstafford's full-sized avatar

Mark Stafford markdstafford

  • Microsoft
  • Redmond, WA
View GitHub Profile
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);
}
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',
using System.Data.Services;
namespace OData101.UpdateTheSvcFileWhenBinDeploying
{
public class BinDeploy : DataService&lt;DummyContext&gt; { }
public class DummyContext { }
}
@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
@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 / 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.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);
}
<!--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
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 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;