Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active December 13, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4959829 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4959829 to your computer and use it in GitHub Desktop.
ORMS: CoolStorage example
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