/// <summary> /// Executes SQL command and returns results as collection of values of specified type /// </summary> /// <typeparam name="T">Type of result items</typeparam> /// <param name="sql">SQL command text</param> /// <param name="parameters">Parameters to execute the SQL command</param> /// <returns>Collection of values of specified type</returns> public virtual IList <T> Query <T>(string sql, params DataParameter[] parameters) { using (var currentConnection = new NopDataConnection()) { return(currentConnection.Query <T>(sql, parameters)?.ToList() ?? new List <T>()); } }
/// <summary> /// Get the current identity value /// </summary> /// <typeparam name="T">Entity</typeparam> /// <returns>Integer identity; null if cannot get the result</returns> public virtual int?GetTableIdent <T>() where T : BaseEntity { using (var currentConnection = new NopDataConnection()) { var tableName = currentConnection.GetTable <T>().TableName; var result = currentConnection.Query <decimal?>($"SELECT IDENT_CURRENT('[{tableName}]') as Value") .FirstOrDefault(); return(result.HasValue ? Convert.ToInt32(result) : 1); } }