Added Any() extension to MDM

This commit is contained in:
Mark McDowall 2013-06-03 22:09:16 -07:00
parent 047e53179d
commit 6694aaeded
1 changed files with 25 additions and 0 deletions

View File

@ -568,6 +568,31 @@ namespace Marr.Data.QGen
return this; return this;
} }
public virtual bool Any(Expression<Func<T, bool>> filterExpression)
{
bool useAltNames = _isFromView || _isGraph;
bool addTablePrefixToColumns = true;
_whereBuilder = new WhereBuilder<T>(_db.Command, _dialect, filterExpression, _tables, useAltNames, addTablePrefixToColumns);
return Any();
}
public virtual bool Any()
{
SqlModes previousSqlMode = _db.SqlMode;
// Generate a row count query
string where = _whereBuilder != null ? _whereBuilder.ToString() : string.Empty;
bool useAltNames = _isFromView || _isGraph || _isJoin;
IQuery query = QueryFactory.CreateRowCountSelectQuery(_tables, _db, where, SortBuilder, useAltNames);
string queryText = query.Generate();
_db.SqlMode = SqlModes.Text;
int count = Convert.ToInt32(_db.ExecuteScalar(queryText));
_db.SqlMode = previousSqlMode;
return count > 0;
}
#endregion #endregion