Created
March 11, 2012 18:40
-
-
Save kradcliffe/2017635 to your computer and use it in GitHub Desktop.
Very annoying ObjectQuery API quirk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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