Skip to content

Instantly share code, notes, and snippets.

View mikebeaton's full-sized avatar

Mike Beaton mikebeaton

View GitHub Profile
@mikebeaton
mikebeaton / AnotherAnswer1.sql
Created September 3, 2019 15:37
'Another Answer' article, gist #1
INSERT INTO dbo.Categories (CategoryName, Description)
VALUES (@CategoryName, @Description)
SELECT SCOPE_IDENTITY()
@mikebeaton
mikebeaton / AnotherAnswer2.sql
Created September 3, 2019 15:38
'Another Answer' article, gist #2
INSERT INTO SCOTT.DEPT (DNAME, LOC, DEPTNO)
VALUES (:DNAME, :LOC, SCOTT.DEPT_SEQ.nextval);
SELECT SCOTT.DEPT_SEQ.currval FROM DUAL;
@mikebeaton
mikebeaton / AnotherAnswer3.cs
Created September 3, 2019 15:39
'Another Answer' article, gist #3
public class Film
{
// the primary key
public int Id;
public string Title;
public string Description;
// DB column has default of the current date-time
@mikebeaton
mikebeaton / AnotherAnswer4.cs
Created September 3, 2019 15:40
'Another Answer' article, gist #4
db.Insert(new Film("Star Wars", "A long time ago…."));
@mikebeaton
mikebeaton / AnotherAnswer5.cs
Created September 3, 2019 15:41
'Another Answer' article, gist #5
var films = new MightyOrm<Film>(connectionString);
var film = films.New(new {
Title = "Star Wars",
Description = "A long time ago..."
});
var db = new MightyOrm(connectionString, "Film", "FilmID");
var film = db.Single(47);
film.Description = "This is a better description";
db.Save(film);
var films = db.All(new { Director = "Spielberg" });
foreach (var film in films) Console.WriteLine(film.Title);
var result = db.ExecuteProcedure("my_add_proc", inParams: new { a = 1, b = 2}, outParams: new { c = (int?)null });
Console.WriteLine(result.c); // 3
var db = new MightyOrm<Film>(connectionString, primaryKeys: "FilmID");
var films = db.All();
foreach (Film film in films)
{
Console.WriteLine($"{film.Title}: {film.Description}");
}
[DatabaseTable("films")]
public class Film
{
[DatabaseColumn("film_id")]
public int FilmID;
[DatabaseColumn("film_title")]
public int Title;
}
var db = new MightyOrm(connectionString);
var now = DateTime.Now;
using (var multiple = db.ExecuteMultipleFromProcedure("PurchaseReport",
inParams: new { StartDate = now.AddMonths(6), EndDate = now })
{
multiple.NextResultSet();
foreach (var summary in multiple.CurrentResultSet.ResultsAs<PurchaseReportSummary>())
{
Console.WriteLine($"Total Sales for Report Period: ${summary.Total}");
}