Created
January 10, 2010 19:29
-
-
Save JeremySkinner/273709 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 Customer { | |
| public int Id { get; set; } //assumes public property named "Id" is PK | |
| public string Name { get; set; } //all public read/write properties auto-mapped to db cols | |
| } | |
| //config: | |
| ActiveRecordConfiguration.Configure(cfg => { | |
| cfg.ConnectToSqlServer("(local)", "mydb", "user", "pass"); | |
| cfg.MapTypesFromAssemblyContaining<Customer>(); | |
| //lots of other options... | |
| }); | |
| //usage: | |
| using(ContextScope.Begin()) { //in a web app, this can be transparent using a scope per request | |
| var customer = new Customer { Name = "Jeremy" }; | |
| customer.Save(); | |
| } //changes committed on scope disposal | |
| using(ContextScope.Begin()) { | |
| var cust = Customer.FindById(1); //normal AR-style operations | |
| } | |
| //testability: | |
| var fakeData = new[] { new Customer { Id = 1 }, new Customer { Id = 2 } }; | |
| using(Customer.Fake(fakeData)) { //replaces underlying data access with in-memory collection | |
| var cust = Customer.FindById(1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment