Skip to content

Instantly share code, notes, and snippets.

@kradcliffe
Created March 11, 2012 18:40
Show Gist options
  • Save kradcliffe/2017635 to your computer and use it in GitHub Desktop.
Save kradcliffe/2017635 to your computer and use it in GitHub Desktop.
Very annoying ObjectQuery API quirk
// Convenience property on MyDbContext for easy access to the ObjectContext
public ObjectContext ObjectContext
{ get { return ((IObjectContextAdapter)this).ObjectContext; } }
/* The actual problem - goes against the expected fluent API here */
var ctx = new MyDbContext().ObjectContext;
ObjectQuery<TModel> query = ctx.CreateObjectSet<TModel>();
query.Include("Site"); // Silently DOESN'T INCLUDE "Site"
query.OrderBy("it." + orderBy); // Silently DOESN'T ORDER BY our orderBy
// Instead, you need to remember to use the API this way
query = query.Include("Site");
query = query.OrderBy("it." + orderBy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment