This may be a basic question, but is System.Data.SqlClient Specific to SQL Server Only?
I would like to use the System.Data.SqlClient.SortOrder as a method parameter to my repository interface IRepository.Find(), but don’t want to use a SQL Server specific argument.
Is there a vendor-neutral version of the SortOrder enum?
For now, I am just using a string parameter called sortOrder which just takes the value “asc” or “desc” or just create my own enum.
Here is the implementation of the method in question:
public ICollection<T> Find(Expression<Func<T, bool>> predicate, int pageNumber, int size, Expression<Func<T, object>> orderBy, string sortOrder, out int count, params Expression<Func<T, object>>[] fetchSelectors)
{
count = (this.DbSet as IQueryable<T>).Count(predicate);
if (size < 1 || size > count)
{
throw new ArgumentOutOfRangeException("size");
}
var maxPageNumber = (count + size - 1) / size;
if (pageNumber < 1 || pageNumber > maxPageNumber)
{
throw new ArgumentOutOfRangeException("pageNumber");
}
if (sortOrder != "asc" && sortOrder != "desc")
{
throw new ArgumentException("sortOrder");
}
var skipCount = pageNumber * size;
var query = BuildQuery(predicate, fetchSelectors);
query = sortOrder == "asc" ? query.OrderBy(orderBy) : query.OrderByDescending(orderBy);
return query.Skip(skipCount).Take(size).ToList();
}
From MSDN, yes this is SQL Server specific.
Collation will likely be provider-specific, although the semantics (ASC/DESC) are common.