Last active
December 13, 2015 18:59
-
-
Save yetanotherchris/4959829 to your computer and use it in GitHub Desktop.
ORMS: CoolStorage 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
using Activa.CoolStorage; | |
[MapTo("people")] | |
public class Person : CSObject<Person, Guid> | |
{ | |
[MapTo("id")] | |
public abstract Guid Id { get; set; } | |
[MapTo("name")] | |
public abstract string Name { get; set; } | |
[MapTo("email")] | |
public abstract string Email { get; set; } | |
} | |
public class PersonManager | |
{ | |
public static void Example() | |
{ | |
// Requires app.config/web.config settings: | |
// <CoolStorage> | |
// <add key="Connection" value="CSDataProviderSqlServer,Activa.CoolStorage.SqlServer / database=dev;uid=dev;password=password;server=(local)"/> | |
// </CoolStorage> | |
// Save example | |
Person person = Person.New(); | |
person.Name = "John"; | |
person.Email = "john@aol.com"; | |
person.Save(); | |
// Some examples of loading | |
Person p = Person.ReadFirst("Name='John'"); | |
CSList<Person> list = Person.List(); | |
int count = list.Count; | |
// An example of object notation (if Person had an Address object as | |
// a property) | |
list = Person.List("Address.Town = 'London'"); | |
// Paging | |
int page = 1; | |
int itemsPerPage = 10; | |
// e.g. (10 * 3) - 10 | |
int start = (itemsPerPage * page) - itemsPerPage; | |
list = Person.List().Range(start, itemsPerPage); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment