Last active
December 13, 2015 18:59
-
-
Save yetanotherchris/4959794 to your computer and use it in GitHub Desktop.
ORMs: subsonic example
This file contains 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
// This class is autogenerated for you by SubSonic, so it's a lot larger than this. | |
public class Person | |
{ | |
public Guid Id { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
} | |
public class PersonManager | |
{ | |
public static void Example() | |
{ | |
// Requires app.config/web.config settings (a SubSonicService node) | |
int page = 1; | |
int itemsPerPage = 10; | |
// Save example | |
Person person = new Person(); | |
person.Id = Guid.NewGuid(); | |
person.Name = "John"; | |
person.Email = "john@aol.com"; | |
person.Save(); | |
// Number of records | |
int count = new Select().From(Person.Schema).GetRecordCount(); | |
// All items | |
IList<Person> list = Select().From(Person.Schema).OrderAsc("Name").ExecuteTypedList<Person>(); | |
// Paging | |
SubSonic.SqlQuery q = new Select().From(Person.Schema).InnerJoin(Address.Schema); | |
// You can append predicates like below | |
q = q.Where(Address.StreetColumn).IsEqualTo("Long Road"); | |
list = q.Paged(page, itemsPerPage).ExecuteTypedList<FeedItem>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment