Last active
August 29, 2015 14:08
-
-
Save tombowers/85c8cdd537208954e30d to your computer and use it in GitHub Desktop.
AppCore snippets
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
const string sql = "SELECT [layout_key], [layout_name] FROM [layout]"; | |
var layouts = new MsSqlDataSource(_connectionString) | |
.Execute(sql) | |
.Select(row => | |
new Layout( | |
row.GetValueOrDefault<int>("layout_key"), | |
row.GetValueOrDefault<string>("layout_name") | |
) | |
); |
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
var sqlDataSource = new MsSqlDataSource(_connectionString); | |
var firstId = sqlDataSource.ExecuteScalar<int>("SELECT TOP 1 id FROM Students"); |
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
var activeStatus = row.GetValueOrDefault<ProductStatus>("product_status"); |
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
var layouts = new List<Layout>(); | |
using (var connection = new SqlConnection(_connectionString)) | |
{ | |
try | |
{ | |
connection.Open(); | |
const string sql = "SELECT [layout_key], [layout_name] FROM [layout]"; | |
using (var command = new SqlCommand(sql, connection)) | |
{ | |
using (var reader = command.ExecuteReader()) | |
{ | |
while (reader.Read()) | |
{ | |
var layoutKey = (int)reader["layout_key"]; | |
var layoutName = (string)reader["layout_name"]; | |
layouts.Add(new Layout(layoutKey, layoutName, layoutWidth)); | |
} | |
return layouts; | |
} | |
} | |
} | |
catch (Exception) | |
{ | |
// ... | |
} | |
} |
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 enum ProductStatus | |
{ | |
[Description("a")] | |
Active, | |
Inactive, | |
[Description("d")] | |
Discontinued | |
} |
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
var activeStatus = "a".ToEnum<ProductStatus>(); | |
var inactiveStatus = "Inactive".ToEnum<ProductStatus>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment