Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created June 7, 2012 11:19
Show Gist options
  • Save tugberkugurlu/2888280 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/2888280 to your computer and use it in GitHub Desktop.
public static IEnumerable<T> Query<T>(this DbContext @this, System.Linq.Expressions.Expression<Func<T, bool>> predicate = null)
where T : class {
var query = (predicate != null) ? @this.Set<T>().Where(predicate) : @this.Set<T>();
var cmd = new SqlCommand();
cmd.Connection = (SqlConnection)(@this.Database.Connection);
//gets the generated t-sql
cmd.CommandText = query.ToString();
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment