/// <summary> /// Map to an existing instance /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection"></param> /// <param name="query"></param> /// <param name="ignoreExtraRows"></param> /// <param name="target"></param> /// <param name="parameters"></param> /// <returns></returns> protected bool TryGetSingle <T>( object query, T target, bool ignoreExtraRows, params object[] parameters) { var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters); wrapper.ExpectSelectQuery(); bool looped = false; using (IDataReader reader = wrapper.RunQuery(StorageController)) { while (reader.Read()) { if (looped) { throw new IQException("More than one record was returned by the Single<T> query"); } reader.Map(target); looped = true; if (ignoreExtraRows) { break; } } } return(looped); }
protected bool TryGetSingle <T>( object query, out T target, bool ignoreExtraRows, params object[] parameters) { var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters); wrapper.ExpectSelectQuery(); T output = default(T); bool looped = false; using (IDataReader reader = wrapper.RunQuery(StorageController)) { while (reader.Read()) { if (looped) { throw new IQException("More than one record was returned by the Single<T> query"); } output = reader.Map <T>(); looped = true; if (ignoreExtraRows) { break; } } } if (!looped) { target = (T)Utils.DefaultValue(typeof(T)); return(false); } else { target = output; return(true); } }
public int QueryScalar(string query, params object[] parameters) { var wrapper = new SqlQueryParser <object>(0, query, parameters); return(wrapper.RunQueryScalar(StorageController)); }
public IDataReader Query(string query, params object[] parameters) { var wrapper = new SqlQueryParser <object>(0, query, parameters); return(wrapper.RunQuery(StorageController)); }
public int Count <T>(object query, params object[] parameters) { var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters); return(StorageController.Count(wrapper.Connection, wrapper.Query.GetQuery(), wrapper.Query.Parameters)); }
public IEnumerable <T> Select <T>(object query, params object[] parameters) { var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters); return(wrapper.RunQuery(StorageController).MapAll <T>(wrapper.Buffered)); }
public int Delete <T>(object query, params object[] parameters) { var wrapper = new SqlQueryParser <T>(QueryType.Delete, query, parameters); return(wrapper.RunQueryScalar(StorageController)); }