Created
February 14, 2016 19:49
-
-
Save Jtorrecilla/c79bc4f309760a1e1dc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SqlServerQueryGeneration : ISqlQueryGeneration | |
| { | |
| public string GetInsertQuery(IEnumerable<string> columns, string table, bool returnId = false) | |
| { | |
| if (!columns.Any()) | |
| { | |
| throw new ArgumentNullException("Columns are required"); | |
| } | |
| if (string.IsNullOrWhiteSpace(table)) | |
| { | |
| throw new ArgumentNullException("Table is required"); | |
| } | |
| string scopeIdentity = string.Empty; | |
| if (returnId) | |
| scopeIdentity = " SELECT SCOPE_IDENTITY()"; | |
| return string.Format("INSERT INTO [{0}] ({1}) VALUES({2}){3}", table, string.Join(",", columns), string.Join(",", columns.Select(c => string.Format("@{0}", c))), scopeIdentity).ToUpper(); | |
| } | |
| public string GetSelectQuery(IEnumerable<string> columns, string table) | |
| { | |
| if (!columns.Any()) | |
| { | |
| throw new ArgumentNullException("Columns are required"); | |
| } | |
| if (string.IsNullOrWhiteSpace(table)) | |
| { | |
| throw new ArgumentNullException("Table is required"); | |
| } | |
| return string.Format("SELECT {0} FROM [{1}]", string.Join(",", columns),table).ToUpper(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment