Skip to content

Instantly share code, notes, and snippets.

@markrendle
Created June 4, 2014 14:21
Show Gist options
  • Save markrendle/d726d04e2d02d2ba4509 to your computer and use it in GitHub Desktop.
Save markrendle/d726d04e2d02d2ba4509 to your computer and use it in GitHub Desktop.
Simple.Data v2 teaser
class Tease
{
private readonly dynamic _db = Database.Open();
public async void DoSomeStuff()
{
// Async by default
Customer customer = await _db.Customers.Get(42).WithOrders();
// Batch operations
var batch = Batch.Create()
.Add(db => {
customer = db.Customers.Insert(Name: "ACME");
customer.Orders.Add(await db.Orders.Insert(Text: "Rocket Skates", CustomerId = customer.Id));
customer.Orders.Add(await db.Orders.Insert(Text: "TNT", CustomerId = customer.Id));
);
await batch.Execute(_db); // Runs with a single connection open/close
// Metadata
var metadata = MetadataProvider.For(_db);
var tables = await metadata.Tables().ToList();
}
}
class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Order> { get; set; }
}
class Order
{
public int Id { get; set; }
public DateTimeOffset Date { get; set; }
public string Text { get; set; }
}
@ronnyek
Copy link

ronnyek commented Sep 20, 2015

Do you not need a property name for customers orders?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment