Skip to content

Instantly share code, notes, and snippets.

@tombowers
Last active August 29, 2015 14:08
Show Gist options
  • Save tombowers/85c8cdd537208954e30d to your computer and use it in GitHub Desktop.
Save tombowers/85c8cdd537208954e30d to your computer and use it in GitHub Desktop.
AppCore snippets
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")
)
);
var sqlDataSource = new MsSqlDataSource(_connectionString);
var firstId = sqlDataSource.ExecuteScalar<int>("SELECT TOP 1 id FROM Students");
var activeStatus = row.GetValueOrDefault<ProductStatus>("product_status");
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)
{
// ...
}
}
public enum ProductStatus
{
[Description("a")]
Active,
Inactive,
[Description("d")]
Discontinued
}
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