Skip to content

Instantly share code, notes, and snippets.

@mythz
Created February 25, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/c9280982d3699ca1c02e to your computer and use it in GitHub Desktop.
Save mythz/c9280982d3699ca1c02e to your computer and use it in GitHub Desktop.
OrmLite Extensions to help with intelli-sense in R#-less VS.NET projects, use 'x' suffix for lambda's and 'q' suffix for SqlExpressions
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
namespace ServiceStack.OrmLite
{
public static class OrmLiteExtensions
{
/* Extension methods for API's providing lambda's use 'x' suffix to help with intelli-sense */
public static List<T> Selectx<T>(this IDbConnection dbConn, Expression<Func<T, bool>> predicate)
{
return dbConn.Select<T>(predicate);
}
public static T Singlex<T>(this IDbConnection dbConn, Expression<Func<T, bool>> predicate)
{
return dbConn.Single<T>(predicate);
}
public static TKey Scalarx<T, TKey>(this IDbConnection dbConn, Expression<Func<T, TKey>> field)
{
return dbConn.Scalar<T,TKey>(field);
}
public static TKey Scalarx<T, TKey>(this IDbConnection dbConn,
Expression<Func<T, TKey>> field, Expression<Func<T, bool>> predicate)
{
return dbConn.Scalar<T, TKey>(field, predicate);
}
public static long Countx<T>(this IDbConnection dbConn, Expression<Func<T, bool>> expression)
{
return dbConn.Count<T>(expression);
}
public static List<T> LoadSelectx<T>(this IDbConnection dbConn, Expression<Func<T, bool>> predicate, string[] include = null)
{
return dbConn.LoadSelect<T>(predicate, include);
}
/* Extension methods for API's providing SqlExpression<T> use 'q' suffix to help with intelli-sense. */
public static List<T> Selectq<T>(this IDbConnection dbConn, Func<SqlExpression<T>, SqlExpression<T>> expression)
{
return dbConn.Select<T>(expression);
}
public static List<Into> Selectq<Into, From>(this IDbConnection dbConn, Func<SqlExpression<From>, SqlExpression<From>> expression)
{
return dbConn.Select<Into, From>(expression);
}
public static T Singleq<T>(this IDbConnection dbConn, Func<SqlExpression<T>, SqlExpression<T>> expression)
{
return dbConn.Single<T>(expression);
}
public static long Countq<T>(this IDbConnection dbConn, Func<SqlExpression<T>, SqlExpression<T>> expression)
{
return dbConn.Count<T>(expression);
}
public static List<T> LoadSelectq<T>(this IDbConnection dbConn, Func<SqlExpression<T>, SqlExpression<T>> expression, string[] include = null)
{
return dbConn.LoadSelect<T>(expression, include);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment