Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ORMS: ActiveRecord example
[ActiveRecord("people")]
public class Person : ActiveRecordBase<Person>
{
[PrimaryKey(PrimaryKeyType.Guid)]
public Guid Id { get; set; }
[Property("name")]
public string Name { get; set; }
[Property("email")]
public string Email { get; set; }
}
public class PersonManager
{
public static void Example()
{
// Requires app.config/web.config settings (an activerecord 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 (can't use the Person class)
int count = ActiveRecordMediator<Person>.Count();
// All items
IList<Person> list = Person.FindAll();
// Paging
list = Person.SlicedFindAll(page, itemsPerPage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.